Changing numbers to actual dates
2 次查看(过去 30 天)
显示 更早的评论
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?
0 个评论
采纳的回答
dpb
2018-4-11
>> 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 个评论
dpb
2018-4-11
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Dates and Time 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!