Borrar filtros
Borrar filtros

Ploting vs. 24hour day time (string that resets to zero and repeats)

1 visualización (últimos 30 días)
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.

Respuesta aceptada

Star Strider
Star Strider el 29 de Ag. de 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 comentarios
Star Strider
Star Strider el 6 de Sept. de 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.

Iniciar sesión para comentar.

Más respuestas (1)

dpb
dpb el 29 de Ag. de 2015
Editada: dpb el 29 de Ag. de 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...

Categorías

Más información sobre Dates and Time en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by