plotting Timeseries, setting xlim only to the range of data

11 vues (au cours des 30 derniers jours)
Meh
Meh le 24 Fév 2014
Modifié(e) : per isakson le 28 Fév 2014
while ploting a timeseries Matlab automatically takes xlim values beyond the actual data time limit. For example I have time start date and end as
beginTime='12-OCT-2012 14:00:00';
finishTime='12-OCT-2012 18:00:00'
but when I plot I get plot with xlim from '12-OCT-2012 13:55:12' to '12-OCT-2012 18:43:12'. How can I fix the xlim to exactly the time range of my data ?

Réponses (1)

per isakson
per isakson le 24 Fév 2014
Modifié(e) : per isakson le 24 Fév 2014
Warning: Not tested
date_frmt = 'dd-mmm-yyyy HH:MM:SS';
set(axes_handle,'XLim',[datenum(beginTime,date_frmt),datenum(finishTime,date_frmt)])
  2 commentaires
Meh
Meh le 25 Fév 2014
Modifié(e) : Meh le 25 Fév 2014
Thanks Per, but I am getting strange dates on my plot. XLim is now from 18-Mar-4025 14:00:00 to 18-Mar-4025 18:00:00. Any suggestion? I used gca instead of axes_handle, but I don't think it plays any role, does it?
per isakson
per isakson le 28 Fév 2014
Modifié(e) : per isakson le 28 Fév 2014
I didn't pay enough attention to the difference between "timeseries" and "time series". The former is a Matlab class and the latter is a signal that depends on time. I've never used "timeseries" seriously.
With "time series", i.e. the old way, there is no problems:
date_frmt = 'dd-mmm-yyyy HH:MM:SS';
beginTime='12-OCT-2012 14:00:00';
finishTime='12-OCT-2012 18:00:00';
t = [ datenum(beginTime,date_frmt) : 1/(24*60) : ...
datenum(finishTime,date_frmt) ];
y = randn( size(t) );
plot( t, y )
axes_handle = gca;
datetick
set(axes_handle,'XLim', ...
[datenum(beginTime,date_frmt),datenum(finishTime,date_frmt)])
.
The class "timeseries" is a bit too smart to my taste.
  • Firstly, I cannot recreate the time axis you describe.
  • Secondly, I'm not sure whether datetick and/or set(h,'XLim'...) should be used - most likely not.
I tried
ts = timeseries( y, t );
ts.TimeInfo.Format = date_frmt;
ts.Time = ts.Time - ts.Time(1); % ????
figure
plot( ts )
Obviously, serial date numbers are not the default with timeseries.
>> ts.TimeInfo
tsdata.timemetadata
Package: tsdata
Non-Uniform Time:
Length 241
Time Range:
Start 0 seconds
End 1.666667e-01 seconds
Common Properties:
Units: 'seconds'
Format: 'dd-mmm-yyyy HH:MM:SS'
StartDate: ''
Most likely, the problems you see depend one the values of the properties, Start, Unit and/or StartDate.
"18-Mar-4025 14:00:00" is approx. two times 2013. Probably, a start value is "added" auto-magically to the XLim values of set(axes_handle,'XLim', ....
/over

Connectez-vous pour commenter.

Catégories

En savoir plus sur Time Series Events dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by