MATLAB Answers

Using @range in timetable when having NaN's

14 views (last 30 days)
Robert on 12 Sep 2017
Commented: Robert on 14 Sep 2017
I am trying to calculate daily mean and daily range from a timetable:
'25-Feb-2008 00:00:00' 29.1580000000000
'25-Feb-2008 00:30:00' 29.1350000000000
'25-Feb-2008 01:00:00' 29.1400000000000
'25-Feb-2008 01:30:00' 29.1350000000000
'25-Feb-2008 02:00:00' 28.9070000000000
By using:
It works fine, for @nanmean, for days with data and some NaN's, or the entire day with only NaN's.
But this doesn't work for @range, do you know of any range function to use in timetable that works similar to nanmean?
I also tried:
But received this error: Error using timetable/retime Too many output arguments.
And this:
But received this error:
Error using timetable/retime (line 103)
Aggregation method 'bounds' returned value that did not have exactly one row.
Suggestions are welcome. Thanks!


Show 1 older comment
Robert on 12 Sep 2017
Thanks, If I understand what you propose, I will end with missing days at the end of the calculation, which is what I do not need. Instead, I want to be able to have NaN as a value for when a day has only NaNs. Sorry if I was not clear the first time.
KSSV on 12 Sep 2017
That case you needs to fill the NaN's
Robert on 12 Sep 2017
Replacing NaNs with a number will help when full days (at minutes time steps) happen, but will affect the days that have some data and NaNs (mean calculation). I appreciate your suggestions.

Sign in to comment.

Accepted Answer

Peter Perkins
Peter Perkins on 14 Sep 2017
Robert, it's not clear what you are looking for, or what you mean by "doesn't work". As KSSV says, range ignores NaNs, so it's not clear what problem you are running into.
If you are doing aggregation with synchronize, you can write your own function to do whatever you want. You could easily write a v ersion of range that did NOT ignore NaNs, for example.

  1 Comment

Robert on 14 Sep 2017
Thanks, I am using this function now:
function y = nanrange(x)
y = range(x);
if isempty(y)
y = nan;

Sign in to comment.

More Answers (0)

Sign in to answer this question.