MATLAB: For the x axis I have time it starts from 0,1,2 hours I need to change it to real time 1:30am

time seriesx axis

My x aixs is in hours from 0,1,2,3,…. I need to change it to it's actual time-i.e. 1:30 is time 0, 2:30 is time 1 hour, 3:30 is time 2 hour and so on…

Best Answer

  • t = hours(x + 3/2);
    t.Format = 'hh:mm';
    plot(t, y)
    However, you would do things a bit differently if you have more than 22 hours and you want time of day to be displayed instead of number of hours: in such a case you would also want date information to be displayed. You would use datetime() for that, such as
    t = datetime(MidNight_Of_First_Day) + hours(x + 3/2);
    t.Format = 'MMM d HH:mm';
    plot(t, y)