How can I update x-axis limit of a TIMESERIES plot in MATLAB 7.8 (R2009a)?
4 views (last 30 days)
Show older comments
I want to update x-axis limit of a TIMESERIES plot. However, using serial date numbers for minimum and maximum limits of the x-axis does not work. For example, I create a TIMESERIES plot:
b = timeseries(rand(1000,1), rand(1000,1)+[0:999]');
b.TimeInfo.StartDate = datestr( now );
f1 = figure;
plot(b);
Updating XLIM with the following:
xBegin = datenum(b.TimeInfo.StartDate,'dd-mmm-yyyy HH');
xEnd = datenum(b.TimeInfo.StartDate,'dd-mmm-yyyy HH')+ 0.0417;
xlim([xBegin xEnd])
incorrectly updates the x-axis limits.
Accepted Answer
MathWorks Support Team
on 15 Sep 2009
As of MATLAB 7.8 (R2009a), the XDATA of a TIMESERIES plot is expressed in days relative to the StartDate of TIMESERIES (DATENUM(b.TimeInfo.StartDate) in the example) and not in absolute DATENUM values. This avoids rounding problem in plotting TIMESERIES with numerically small time values expressed relative to a large StartDate offset. To update the x-axis limits, use the time vector itself after converting to days, for example:
xBegin = 0; % starting x-limit relative to the StartDate
xEnd = 0.0417; % where 0.0417 is a fractional number of a day
xlim([xBegin xEnd])
0 Comments
More Answers (0)
See Also
Categories
Find more on Dates and Time in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!