how to set x axis into hours

11 visualizaciones (últimos 30 días)
Innosens
Innosens el 15 de Jun. de 2012
i have problem . how to i set the x axis into hour. i have 10080 data and each one represents one minute of data. i want to represents x axis with 24 hour, how can I make like that

Respuesta aceptada

Walter Roberson
Walter Roberson el 15 de Jun. de 2012
xtickat = 0:60:length(YourData)-1; %every hour from 00:00
set(gca, 'XTick', xtickat, 'XTickLabel', cellstr( num2str( mod(round(xtickat .' ./ 60),24) ) ) )
This will use hour 0, 1, 2, ... 23, 0, 1, 2, ... 23, and so on, with no indication of the day of the week (as the question asked for x axis to be in 24 hour, not for day and hour)
This will try to produce 168 ticks, which might perhaps be too much for your purposes. If so you can increase the 60 in xtickat to a more appropriate number such as 360 (6 hours).
  6 comentarios
Innosens
Innosens el 16 de Jun. de 2012
sory i can't understand what do you mean, where i put the subtract one and add one.
Thanks before...
Walter Roberson
Walter Roberson el 16 de Jun. de 2012
mod(round(xtickat .' ./ 60),24)
would become
1 + mod(round(xtickat .' ./ 60) - 1,24)

Iniciar sesión para comentar.

Más respuestas (1)

Sean de Wolski
Sean de Wolski el 15 de Jun. de 2012
Something along the lines of:
set(gca,'xticklabel',num2cell(num2str((0:2:22)'),2)')
  2 comentarios
Walter Roberson
Walter Roberson el 15 de Jun. de 2012
Why use num2cell for that?
set(gca, 'xticklabel', cellstr( num2str((0:2:22).') ) )
However, this has the problem that you need exactly the matching number of Xtick values
Sean de Wolski
Sean de Wolski el 15 de Jun. de 2012
CELLSTR is sweet (and new to me!). I'd heard of ISCELLSTR, but not CELLSTR.

Iniciar sesión para comentar.

Categorías

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

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by