Hi, I have 16000 sampled data. I want to plot it vs time in HH:mm format (ex 15:33)
I know when the first data point was taken (12:33:00) and I sampled 1 per 10 seconds.
I cant figure out how to do this

 採用された回答

Ankit
Ankit 2022 年 1 月 24 日

0 投票

You need to change the format using datetick.
date={'15:10:34.600 AM 2/26/2017','15:20:34.700 AM 2/26/2017','15:30:34.800 AM 2/26/2017','15:40:34.900 AM 2/26/2017'};
timeFormat='HH:MM:SS.FFF AM mm/dd/yyyy';
xdatenum=datenum(date,timeFormat);
data=0:3;
plot(xdatenum,data,'*');
datetick('x','HH:MM');

6 件のコメント

Ron Amar
Ron Amar 2022 年 1 月 24 日
oh great thanks.
just 1 more question - this 'date' string vector I have to manually make? how do i genarate it?
Ankit
Ankit 2022 年 1 月 24 日
編集済み: Ankit 2022 年 1 月 24 日
You can use datetime Arrays to represent dates and times. I edited the code a bit as per your request. Please refer this link to know more: Arrays that represent points in time - MATLAB - MathWorks Deutschland
t = datetime(0,0,0,15,33,1:100:5000); % Y,M,D,HH,MM,SS, sampling 1 per 10s
x = randn(50, 1);
plot(t, x)
datetick('x', 'HH:MM')
xlim(t([1 end]))
Ron Amar
Ron Amar 2022 年 1 月 24 日
you're the best Ankit thank you so much!
Ankit
Ankit 2022 年 1 月 24 日
Hi @Ron Amar if it works could you please accept the answer! Thanks
Steven Lord
Steven Lord 2022 年 1 月 24 日
Instead of using a datetime, which requires date information, I'd use a duration array to plot this data.
t = duration(15, 33, 1:100:5000);
x = randn(50, 1);
plot(t, x)
xlim(t([1 end]))
Change the Format of the duration array to change how it is displayed as labels.
t = duration(15, 33, 1:100:5000, 'Format', 'hh:mm'); % no second data
x = randn(50, 1);
plot(t, x)
xlim(t([1 end]))
Ankit
Ankit 2022 年 1 月 24 日
@Steven Lord thanks for your suggestion. now I know one more way to achieve this :)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeGraphics Performance についてさらに検索

タグ

質問済み:

2022 年 1 月 24 日

コメント済み:

2022 年 1 月 24 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by