plotting Timeseries, setting xlim only to the range of data
12 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 ?
0 comentarios
Respuestas (1)
per isakson
el 24 de Feb. de 2014
Editada: per isakson
el 24 de Feb. de 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 comentarios
per isakson
el 28 de Feb. de 2014
Editada: per isakson
el 28 de Feb. de 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
Ver también
Categorías
Más información sobre Time Series Events en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!