Plotting time series with NaN?

조회 수: 8 (최근 30일)
Marian
Marian 2013년 10월 7일
댓글: dpb 2013년 10월 9일
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

채택된 답변

dpb
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
Marian
Marian 2013년 10월 9일
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 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 CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by