Example: 2012 8 23 9 45 44.946 Serial Date Number A single number equal to the number of days since January 0, 0000. For instance, you can use tick_locations = datenum(2012,1) Example: Thursday, Aug9:45:44.946 AM Date Vector A 1-by-6 numeric vector containing the year, month, day, hour, minute, and second. You might have to modify the tick_locations = datenum(2012,1) a bit to get the ticks that you want. % Call datetick again to get the right date labels, use option "keepticks"ĭatetick('mmm yyyy','keeplimits', 'keepticks') Example: Converting a cell string of 10'000 date strings 'dd-mmm-yyyy HH:MM:SS' to the serial date numbers, e.g. Sometimes, the dateticks are not spaced in any sensible way, then you can either try to zoom in and out a little until it snaps to something good, or you have to set the ticks manually: % Set ticks to first day of the months in 2010 The old methods to work with the serial date numbers have been slow already and some less intelligent conversion methods could be 100 times faster (see FEX: DateConvert and FEX: DateStr2Num). It takes the same arguments as datetick, but it hooks into the zoom function and updates the ticks automatically.
You can either call datetick('mmm yyyy','keeplimits')Īgain, after each zooming or panning, or you download datetickzoom from the Matlab file exchange. Easy conversion of a date vector or a serial date number into a date string.
The problem is, the ticks do not update after zooming in. The following Matlab project contains the source code and Matlab examples used for date vector number to iso 8601 date string.
You then plot your data using plot(numeric_date_vec, y)Īnd you let Matlab add the date-ticks automatically by calling datetick('mmm yyyy') You can convert this using numeric_date_vec = datenum(2009, 12, 31) + x However, the conversion is easy, since your format also counts the days, but you count after 31st of December, 2009. Also, this date actually never existed, making it really weird when you want to work with dates that are BC. The numbers itself are a bit awkward, since they represent the "amount of time after, in days", which is a huge number. The best format to use for plots is the "serial date format". The first step is to convert your date-format into one of the standard Matlab date formats.