How to write datetime in a plot?
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
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!!!
Mischa Kim
2014 年 1 月 31 日
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!
Mischa Kim
2014 年 2 月 12 日
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!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の 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)
