Plotting time series with NaN?

6 views (last 30 days)
Marian
Marian on 7 Oct 2013
Commented: dpb on 9 Oct 2013
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

Accepted Answer

dpb
dpb on 7 Oct 2013
Edited: dpb on 8 Oct 2013
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 Comments
Marian
Marian on 9 Oct 2013
ok great! This is finally starting to work! Thanks so much!! It took a bit of playing around, but adding that last line of code, ts1.time=10*ts1.time and removing the line that I had earlier (ts1.time=...) did the trick. This should make the rest of my work go much smoother (hopefully) - so thank you!
dpb
dpb on 9 Oct 2013
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.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!