How to plot time format
7 ビュー (過去 30 日間)
古いコメントを表示
I have two time matrices of t1=3x250 and t3=3x450 with 3 columns representing hour, minute and second as integers. I also have two vectors X1 and X2 of size 1x450 and 1x250 respectively. I know on the SAME graph want to plot X1 and x2 against t1 and t2 where each observation on x axis would read in format hour:minute:second. Probably very easy to do. Could anybody guide me please?
0 件のコメント
回答 (2 件)
Star Strider
2017 年 1 月 14 日
It would be easier with your data.
Here is one possibility with created data:
t1 = [0 1 2; 0 2 3; 1 1 10; 1 39 45]; % Original ‘t1’ ‘Hour Minute Second’ Matrix
t1a = [repmat([2017 0 0], size(t1,1), 1) t1]; % Concatenate With ‘[year month day]’
dnv1 = datenum(t1a); % Convert To Date Numbers
x1 = rand(size(dnv1)); % Data ‘x1’
t2 = [0 2 10; 0 3 5; 1 2 20; 2 30 15]; % Original ‘t2’ ‘Hour Minute Second’ Matrix
t2a = [repmat([2017 0 0], size(t1,1), 1) t2];
dnv2 = datenum(t2a);
x2 = rand(size(dnv2));
figure(1)
plot(dnv1, x1)
hold on
plot(dnv2, x2)
hold off
datetick('x', 'hh:mm:ss', 'keepticks')
1 件のコメント
Steven Lord
2021 年 5 月 4 日
Now you'd probably want to use a duration array.
h = randi(3, 1, 10);
m = randi([0 59], 1, 10);
s = randi([0 59], 1, 10);
D = sort(duration(h, m, s));
data = minutes(D-D(1)).^2; % minutes from start squared
plot(D, data, 'o-')
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Dates and Time についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!