MATLAB: How to plot time on the x-axis if it is from 09pm to 09am (over midnight)

midnightplottime

Hi all,
i like to plot some data and the x-axis should be my timeline beginning from 09pm to 09am. When I tell MATLAB to plot my duration-variable (09pm to 09am in 5 sec steps), it shifts my plot so that the time beginns at midnight instead of 09pm.
Could somebody help me solving this problem and explain how to do it?
Thank you very much!

Best Answer

If you explicitly supply a date, this will not happen. The xtickformat function was introduced in R2016b, so you might not have it, but you can change the XTickLabel property directly.
alltime=linspace(...
datetime(2018,2,24,21,0,0),...
datetime(2018,2,25,09,0,0),...
8640+1);
allHR=randi([50 100],8640,1);
figure(1),clf(1)
plot(alltime,allHR)
xtickformat('hh:mm:ss a')
Edit: changed time steps from 5 minutes to 5 seconds.