How to write datetime in a plot?
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
I want to read a file.csv but my problem is that i don't know how can I represent in a plot the hour.
My goal is to represent a number as a datetime but I don't Know if it's possible to convert it as in the next example:
131212 --> HH:MM:SS --> 13:12:12
And then put this number in that format in an x-axis in a plot.
Thanks!!!
채택된 답변
Mischa Kim
2014년 1월 31일
편집: Mischa Kim
2014년 1월 31일
This should do:
T0 = '131212';
T0Vec = [2000,0,0,str2double(T0(1:2)),str2double(T0(3:4)),str2double(T0(5:6))];
T0Str = datestr(T0Vec,'HH:MM:SS');
댓글 수: 14
Diego
2014년 1월 31일
Thanks for your response Mischa! Your code its works but If I prove my code in your code it doesn't works!
I believe that I don't Know how to pass the time! If you can help me I would be gratefully!
I have this code:
TIME_STAMP (100x1 cell) is like that:
TIME_STAMP 2014/01/16 13:12:12 2014/01/16 13:12:13 2014/01/16 13:12:16 2014/01/16 13:12:17 ...
I only have to work with the time and not with the date.
for i=1:length(TIME_STAMP) p=TIME_STAMP{i}(12); %first value of H f=TIME_STAMP{i}(13); %second value of H q=TIME_STAMP{i}(15); %first value of M r=TIME_STAMP{i}(16); %second value of M s=TIME_STAMP{i}(18); %first value of S t=TIME_STAMP{i}(19); %second value of S
%hours(i)=str2double(strcat(p,f));
%min(i)=str2double(strcat(q,r));
%seconds(i)=str2double(strcat(s,t));
time(i)=str2double(strcat(p,f,q,r,s,t));
%T0Vec = [2000,0,0,strcat(hours(i),min(i),seconds)];
T0Vec(i) = [2000,0,0,str2double(strcat(p,f)),str2double(strcat(q,r)),str2double(strcat(s,t))];
T0Str(i) = datestr(T0Vec(i),'HH:MM:SS');
end
- time (1x100 double) is like that:
131212 131213 131216 131217 ...
The result of my code:
Error: In an assignment A(I) = B, the number of elements in B and I must be the same.
I don't Know how to pass the time! If you can help me I would be gratefully! Once I have the string with the time I want to put into the x label. Thanks!!!
It's hard to see what's going on in your code...
- There is an assignment error: A(I) = B, where does it occur?
- If you already have time as a matrix of doubles, as you point out, simply use
T0 = num2str(time(i));
T0Vec = [2000,0,0,str2double(T0(1:2)),str2double(T0(3:4)),str2double(T0(5:6))];
T0Str = datestr(T0Vec,'HH:MM:SS');
Image Analyst
2014년 1월 31일
Diego, read this http://www.mathworks.com/matlabcentral/answers/13205-tutorial-how-to-format-your-question-with-markup and then copy ALL the red text that you see, so we can give you an informed answer.
Diego
2014년 2월 3일
This is my code! the problem is that T0STr only shows the last position of the string and not appears all the position of the time!
Diego
2014년 2월 3일
I want to represent in x label the first time at 13:12:12 and the increasing of the time with the aim to show the variation of RSSI during the time.
Mischa Kim
2014년 2월 3일
Something like this (see attachment)?
Diego
2014년 2월 3일
It does work!!!! Thanks for your help! I'm very grateful! Thanks again Mischa!!!
Perfect! No problem. Thanks for your time!
Diego
2014년 2월 12일
Mika! I just saw that in your code when I represent the graphic in x label only shows somes values of TIME_STAMP. Theoretically in your code you put all the values of TIME_STAMP but only show until 13.12.26
The first value is 13.12.12, the last value 13.14.18, but only represent since 13.12.12 until 13.12.26.
Do you know what is the problem?
I attach you the code and the csv! Thanks Mika!
I suspect it has to do with the tick spacing. Try
set(gca,'XTickLabel',T0Str,'XTick',1:length(T0Str));
With this setting you force MATLAB to put one label per tick.
Would you mind formally accepting the answer? Thanks.
Diego
2014년 2월 12일
Ok it's perfect your answer but I have many values of TIME_STAMP and it is mixed when I represent it and it's impossible to understand...!
Another more thing, I want show up each value of RSSI in the plot. I know that manually when you represent the graphic you can put these values but one by one, automatically it's possible to do this? Do you know?
Thank you very much for your time Mika!
Mischa Kim
2014년 2월 12일
Yes, that's the problem. There're just too many labels, if you print them all.
About your second question: I am not sure I understand. Do you want to print a label right next to each RSSI data point? If so, check out this answer. If no, please further elaborate.
By the way, my name is Mischa :)
Diego
2014년 2월 12일
Yes I wanna do this! I'll try to do it!
I apologize for the confusion, I want to say Mischa! I was writing so quickly...!
Mischa Kim
2014년 2월 13일
Hello Diego. Good to see you again. Would you mind opening another question? It is not really on the topic of your original question, which would make it challening to find for other users. Plus this thread is getting kind of long.
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Annotations에 대해 자세히 알아보기
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
