How to correct 'xtick' label format in plot of a 'timeseries' object?
조회 수: 2 (최근 30일)
이전 댓글 표시
MathWorks Support Team
2020년 10월 20일
편집: MathWorks Support Team
2024년 8월 29일
The following code creates a plot of "timeseries" object. But the 'xtick' labels are not formatted correctly.
a=rand(1,N);
ym=[[repmat(2000,12,1) (1:12)'];[repmat(2001,12,1) (1:12)']];
disp(ym);
datevec = datenum(ym(:,1),ym(:,2),1);
ts1=timeseries(a, datevec);
ts1.TimeInfo.Format = 'mmm-yyyy';
plot(ts1);
I want them to be labeled in 'mmm-yyyy' format.
채택된 답변
MathWorks Support Team
2024년 7월 29일
편집: MathWorks Support Team
2024년 8월 29일
According to the documentation of 'timeseries' object, the 'timevals' should be in 'datestr' format. Use 'datestr' function to utilize the time vector in required format.
The following code produces the desired plot:
a=rand(1,N);
ym=[[repmat(2000,12,1) (1:12)'];[repmat(2001,12,1) (1:12)']];
disp(ym);
datevec = datenum(ym(:,1),ym(:,2),1);
datevec = datestr(datevec);
ts1=timeseries(a, datevec);
ts1.TimeInfo.Format = 'mmm-yyyy';
plot(ts1);
Please run the below command in the command window of installed MATLAB R2019a version to get release specific documentation to read more about the "timeseries" object:
>> web(fullfile(docroot, 'matlab/ref/timeseries.html'))
Please run the below command in the command window of installed MATLAB R2019a version to get release specific documentation on "satestr" function:
>> web(fullfile(docroot, 'matlab/ref/datestr.html'))
Please follow the below link to search for the required information regarding the current release:
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Time Series Events에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!