Borrar filtros
Borrar filtros

plotting Timeseries, setting xlim only to the range of data

11 visualizaciones (últimos 30 días)
Meh
Meh el 24 de Feb. de 2014
Editada: per isakson el 28 de Feb. de 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 ?

Respuestas (1)

per isakson
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
Meh
Meh el 25 de Feb. de 2014
Editada: Meh el 25 de Feb. de 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 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

Iniciar sesión para comentar.

Categorías

Más información sobre Dates and Time en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by