How to set x axis into hours

I have energy consumption data of more than 3 years for every two seconds (43200 per day). Different households. How do I set the x axis into 24hrs (00:00 - 23:59) and plot each day data on one graph?
Thanks

Respuestas (1)

Sean de Wolski
Sean de Wolski el 23 de Feb. de 2015

0 votos

Something along these lines (R2014b required)
dt = datetime('now')-100:1/24:datetime('now');
hours = hour(dt);
scatter(hours,rand(size(dt)));
ax = gca;
ax.XTick = 1:24;
ax.XTickLabelRotation = -60;

4 comentarios

ccs
ccs el 23 de Feb. de 2015
I'm very sorry but i really dont understand these lines. How do you mean by "an example of the last 100 days"? How about 'now' should that be the same date? I would like to be able to select a date range e.g. startdate = 2012-06-12 and enddate = 2014-12-30.
There is also not much info on xticklabelrotation in R2014b help. I apologize for my weak matlab knowledge....thanks again
Sean de Wolski
Sean de Wolski el 23 de Feb. de 2015
doc datetime
ccs
ccs el 26 de Feb. de 2015
I checked out doc datetime. Like in one of your webinars,I have also run the lines you given up to see what the do. Why does it start plotting on the axes themselves, how do i rectify that? how do i replace 'now' to start plotting automated dates connected to my time vector (datenumbers)? I added this line for hours tick but it does not change (to the lines you gave me). >>datetick('x','HH:MM','keeplimits','keepticks');
Thanks.
ccs
ccs el 26 de Feb. de 2015
How can I make the datetick count from 00:00 to 23:59. This below is dispalying 00:00 for every hour.
>> d= datetime(start_date):1/24:datetime(end_date)+1;
>> hours=hour(d);
>> scatter(hours,rand(size(d)));
>> t=datenum(d);
>> ax=gca;
>> ax.XTick=1:24;
>> datetick(ax,'x','HH:MM','keeplimits','keepticks')

Iniciar sesión para comentar.

Categorías

Preguntada:

ccs
el 23 de Feb. de 2015

Comentada:

ccs
el 26 de Feb. de 2015

Community Treasure Hunt

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

Start Hunting!

Translated by