How can I get MATLAB to display the dates and times on the x-axis of a plot?
I am trying to make a plot that shows the water level (WL) in cm over time, as illustrated in the image:
Right now, the x-axis of my plot just shows indices, but I want it to display the dates and times in the order: year, month, day, hour, minute. The format is not that important as long as it's readable and in that order. I also want to be able to control the ticks, so that the user won't be overwhelmed.
In MATLAB, I've been working with dates in the following way:
- An array that contains the DATES in yyyyMMddhhmm format as numbers.
- Multiple arrays that contain yyyy, MM, dd and so on.
WL and my DATES array have the same length, and they arranged so that WL(i) corresponds to DATES(i). Right now, my code looks like this:
figure(1)
hold on
plot(WL)
xlabel('Date')
ylabel('WL [cm]')


plotthen it can obviously only possibly know to plot it by index. Pass it two arguments. See: Plot Dates and Durations - excaza