MATLAB: How to make a plot show all 24hours, one by one, on the x-axis

datetickplotx-label

Hi. I'm trying to make a plot that should show energy production in every hour of the day. I tried this:
Hours_24 = (0:1:23)
plot(Hours_24, Prodution)
xlabel('Hours') %Legenda x
ylabel('MW') %Legenda y
datetick('x', 'HH')
title('Prodution')
grid on
But the result is that the x-axis only shows 00:00 in every single hour. I don't know what i'm doing wrong.

Best Answer

Hours_24 = (0:1:23)/24;
datetick expects the values to be in serial datenum format, which is in full days, so to get hours shown you need to use hours as fraction of 1 day.