Clear Filters
Clear Filters

Changing numbers to actual dates

3 views (last 30 days)
john doe
john doe on 11 Apr 2018
Commented: dpb on 11 Apr 2018
So I have a set of data for example
A = [4 6 3 6 2 7 3 7 8 10]
with time steps
T = [0 28 56 91 119 147 161 175 203 231]
Where the timesteps correspond to months, so 0 is 7th july, 28 is 4th August and so on.
I can plot these graphs, but I would like the numbers to correspond to the actual dates. How can I do this?

Accepted Answer

dpb
dpb on 11 Apr 2018
>> DT=datetime(2018,7+T.',7)
DT =
10×1 datetime array
07-Jul-2018
07-Nov-2020
07-Mar-2023
07-Feb-2026
07-Jun-2028
07-Oct-2030
07-Dec-2031
07-Feb-2033
07-Jun-2035
07-Oct-2037
>>
Oooops! T (as I kinda' thought) isn't in months; it's days...so
>> DT=datetime(2018,7,7+T.')
DT =
10×1 datetime array
07-Jul-2018
04-Aug-2018
01-Sep-2018
06-Oct-2018
03-Nov-2018
01-Dec-2018
15-Dec-2018
29-Dec-2018
26-Jan-2019
23-Feb-2019
>>
Ah! That looks more realistic!
  3 Comments
john doe
john doe on 11 Apr 2018
I don't suppose you know how to get it working for error bars do you? When I try to plot error bars, I get given the error;
Warning: Error updating ErrorBar.
Undefined function 'double' for input arguments of type
'datetime'. To convert from datetimes to numeric, first
subtract off a datetime origin, then convert to numeric using
the SECONDS, MINUTES, HOURS, DAYS, or YEARS functions.
I am trying to use
errorbar(DT, A, SE)
Where
SE = [0.42 0.76 0.45 0.56 0.345 0.45 0.676 0.456 0.35 0.245]
dpb
dpb on 11 Apr 2018
timedate is quite "ripe" yet; there are still holes that need filling. I suggest throw an enhancement request over the wall via official support link just to get it on record somebody wanted the feature with time axes.
The workaround is to revert to the venerable datenum; it is just a double of a specific magnitude. Then, of course, you have to revert to datetick to get the axis displayed as calendar times; somewhat klunky but it does work.

Sign in to comment.

More Answers (0)

Categories

Find more on Dates and Time in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!