Azzera filtri
Azzera filtri

How to plot time format

8 visualizzazioni (ultimi 30 giorni)
jenka
jenka il 14 Gen 2017
Risposto: Steven Lord il 4 Mag 2021
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?

Risposte (2)

Star Strider
Star Strider il 14 Gen 2017
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 Commento
Raidah Zaman
Raidah Zaman il 4 Mag 2021
Thank you! I was geniunely able to learn from this.

Accedi per commentare.


Steven Lord
Steven Lord il 4 Mag 2021
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-')

Community Treasure Hunt

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

Start Hunting!

Translated by