필터 지우기
필터 지우기

Problem with xlim when having date

조회 수: 6 (최근 30일)
BN
BN 2020년 4월 17일
댓글: BN 2020년 4월 17일
Dear all,
I have a problem with x-axis intervals. I would like to start the x-axis in 1989 and end in 2018; with 5 years intervals. Here what I've done so far, but it seems xlim not working in this case:
clf
startdate_A = datenum('01-01-1989','dd-mm-yyyy');
enddate_A = datenum('01-01-2016','dd-mm-yyyy');
dt_A = linspace(startdate_A,enddate_A,336);
startdate = datenum('01-01-1989','dd-mm-yyyy');
enddate = datenum('01-01-2018','dd-mm-yyyy');
dt = linspace(startdate,enddate,360);
plot(dt_A,DATA_A,'color','g')
datetick('x','yyyy','keepticks')
xlim([startdate:5:enddate])
hold on
plot(dt,DATA_B,'color','b')
datetick('x','yyyy','keepticks')
Here is the error:
Error using xlim (line 31)
Limits must be a 2-element vector of increasing numeric values.
Thank you so much

채택된 답변

Peter O
Peter O 2020년 4월 17일
Hi Behzad,
xlim sets the absolute max and min of the graph that you're looking at. To set the interval for grid lines, use the xticks command.
For your needs, use this with the datetick command:
% Define specific five year spacing of ticks for the 27 years of interest
xtks = linspace(startdate_A,enddate_A,27);
plot(dt_A, DATA_A);
xticks(xtks); % Set ticks for axis
xlim([startdate_A,enddate_A]) % Set limits
datetick('x','yyyy','keepticks');
grid on
  댓글 수: 1
BN
BN 2020년 4월 17일
Dear Peter,
Thank you so much.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

태그

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by