필터 지우기
필터 지우기

xlim not working with datenum??

조회 수: 2 (최근 30일)
aaron Harvey
aaron Harvey 2016년 2월 23일
답변: Titus Edelhofer 2016년 2월 25일
Hi there, I'm trying to set the limits of an x-axis of dates produced in a function. I have two inputs to the function, 'startdate' and 'enddate' which are entered in yyyymmdd format. i have tried the following code to limit the x-axis:
starty = floor(startdate/10000);
startm = floor(rem(startdate,10000)/100);
startd = rem(startdate,100);
xmin=datenum(datetime(starty,startm,startd));
endy = floor(enddate/10000);
endm = floor(rem(enddate,10000)/100);
endd = rem(enddate,100);
xmax=datenum(datetime(endy,endm,endd));
xlim([xmin xmax]);
but i just can't figure out why it doesn't work?? i get no error messages it just doesn't work? i have queried the x limits of the graph produced and get the following:
>> xlim
ans =
1.0e+05 *
7.2592 7.3542
thanks for any help in advance

답변 (2개)

Titus Edelhofer
Titus Edelhofer 2016년 2월 25일
Hi Aaron,
here is an example how it works:
% three years:
t = datenum(2012, 1:36, 1)';
plot(t, rand(size(t)))
% makes it easier to read:
datetick x
% let's wait
pause(5);
% and "zoom" in:
xlim([datenum(2013, 1,1), datenum(2014,1,1)])
Titus

Titus Edelhofer
Titus Edelhofer 2016년 2월 23일
Hi,
I'm not yet sure what is the problem. You limit the X-axis to the following date range:
>> datestr(1e5 * [7.2592 7.3542])
ans =
02-Jul-1987
05-Jul-2013
So what is it that is not working?
Titus
  댓글 수: 3
aaron Harvey
aaron Harvey 2016년 2월 23일
correction, it does limit it if i do it manually just took a while on my slow pc. however my function runs the line of code, but it does nothing.
xlim([xmin xmax]);
when copy the values of xmin and xmax that i created straight from the function and xlim([xmin xmax]) manually entering the datenumbers in the command line it works fine???
Walter Roberson
Walter Roberson 2016년 2월 23일
It is not clear at which point you do the xlim. You need to use it after you plot, or you need to set hold on after you xlim if you want to plot after you set xlim

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

카테고리

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