Changing numbers to actual dates

조회 수: 1 (최근 30일)
john doe
john doe 2018년 4월 11일
댓글: dpb 2018년 4월 11일
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?

채택된 답변

dpb
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
john doe
john doe 2018년 4월 11일
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 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 CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by