Plotting time series with NaN?
5 次查看(过去 30 天)
显示 更早的评论
I am using time series to plot temperature every 10 minutes over the course of a month. The only problem I have is that when I run it, the increments are every minute, as determined by the units. I'm not sure how to use the TimeInfo.Increment coding, considering my t array contains NaN. This is the code I have
ts1 = timeseries(t,1:4032); ts1.Name = 'Temperature vs Time'; ts1.TimeInfo.Units = 'minutes'; ts1.TimeInfo.StartDate='01-Feb-2011'; % Set start date. ts1.TimeInfo.Format = 'dd, HH:MM'; % Set format for display on x-axis. ts1.Time=ts1.Time-ts1.Time(1); % Express time relative to the start date. ts1.TimeInfo.Increment='1/144'; plot(ts1)
and I am getting an error:
Operands to the and && operators must be convertible to logical scalar values.
Error in tsdata.timemetadata/set.Increment (line 168) if ~isempty(input) && isfinite(input) && ~isempty(this.Time_)
Error in att201102 (line 63) ts1.TimeInfo.Increment='1/144';
Before I tried using this Increment code, it plotted the correct points but with a wrongly labeled x-axis (every minute instead of every 10 minutes).I have a feeling the NaN in my t array is the cause of this. Thanks
0 个评论
采纳的回答
dpb
2013-10-7
编辑:dpb
2013-10-8
Before I tried using this Increment code, it plotted the correct points but with a wrongly labeled x-axis (every minute instead of every 10 minutes).I have a feeling the NaN in my t array is the cause of this
You may "have a feeling" but you'd be wrong... :)
plot very nicely just ignores NaN leaving holes in the plot.
If you got one-minute increments, that's because the X-vector is undoubtedly on a range of 1:N instead of actually in minutes.
As I said in answering your previous question on the same subject, if you want a time axis w/ date/time, then the easiest is to convert to datenums and use datetick.
If, otoh, the data are at 10-minute intervals and are none missing (or the missing locations in the time vector are filled w/ NaN), and you want to plot from 0 to length of the data series on a 10 minute interval, just use
t=[0:10:10*(length(x)-1)];
which is, of course, just
t=10*[0:length(x)-1];
for the plot x-axis vector. IOW, build the 10-minute interval into the data.
Or, use 1:length(x) and reset the x-tick labels but this is more work than simply making the time vector and using it.
4 个评论
dpb
2013-10-9
Yes. It seems like it should be so a ts object could be specified w/ a constant dt and units instead of requiring the explicit time vector but that isn't what was implemented.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Axis Labels 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!