Ploting vs. 24hour day time (string that resets to zero and repeats)
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Sina Shojaei
am 29 Aug. 2015
Kommentiert: Star Strider
am 6 Sep. 2015
I want to plot some data that looks like this( i.e, plot(time,x).
time= [ 12 14 16 18 20 22 0 2 4 6 8 10 12 14 16 18 20 22 0 2 4 6 8 10]
X= [ 30 32 34 30 29 26 22 20 18 19 20 28 30 32 34 30 29 26 22 20 18 19 20 28]
but looking for best way to keep order of the data as is. Currently I split the data between 0 times and plot on adjacent subplots which looks ugly. Any suggestions appreciated.
0 Kommentare
Akzeptierte Antwort
Star Strider
am 29 Aug. 2015
I suspect this may be what you want to do:
time = [ 12 14 16 18 20 22 0 2 4 6 8 10 12 14 16 18 20 22 0 2 4 6 8 10];
X = [ 30 32 34 30 29 26 22 20 18 19 20 28 30 32 34 30 29 26 22 20 18 19 20 28];
xt = 1:length(time); % X-Ticks
figure(1)
plot(xt, X)
grid
set(gca, 'XTick', xt, 'XTickLabels', time) % Label X-Axis With ‘time’ Vector
Apologise for the delay — hardware crash on my primary MATLAB computer a couple hour ago, so had to install new to this one.
3 Kommentare
Star Strider
am 6 Sep. 2015
My pleasure!
Not silly — it may not be something you would have likely encountered unless you read the documentation on ‘handle graphics’ in some detail.
Weitere Antworten (1)
dpb
am 29 Aug. 2015
Bearbeitet: dpb
am 29 Aug. 2015
A) Convert times to a datenumber and plot against it instead. Use datetick to format the axis or use the new time class with builtin support in latest release(s), or
B) Plot versus index instead of actual time and set tick mark labels manually -- not particularly elegant so A) is the better option.
dn=datenum(2015,1,1,12+[0:2:2*length(time)-1].',0,0);
plot(dn,X)
xlim([dn(1) dn(end)]), ylim([15 35])
datetick('x','dd-HH','keeplimits')
Above uses arbitrary start date; it's immaterial to simply show times but datenum needs six values. Note the generation of the two-hour increments from the starting point to match the length of the data vector and that plotting is against the date numbers that are monotonic which solves your problem of "what to plot against?".
As noted, there's a new time class but I don't have latest release so can't demonstrate it...
0 Kommentare
Siehe auch
Kategorien
Mehr zu Dates and Time finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!