Plotting time series with NaN?
조회 수: 10 (최근 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에서 Dates and Time에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!