Trying to use retime to sum daily values, but I don't want days that only have NaN values to become 0

16 views (last 30 days)
Rita Leavitt
Rita Leavitt on 9 Jul 2021
Answered: Peter Perkins on 27 Jul 2021
Basically I have a timetable or rainfall values (a column with half-hourly time increments and a column with the rainfall at each time point). I used retime to get daily sums:
sum_rainfall_2018 = retime(rainfall_2018, 'daily','sum');
This mostly works, but I have a number of days that only have NaN values, and retime is summing those days as 0. I need them to stay NaN because I need to know where my gaps are. Is there a simple way to do this?

Answers (2)

Jonas on 10 Jul 2021
weird, the normal behavior of sum is giving NaN if at least one of the summed values is NaN. try @sum instead of 'sum' and if this also does not work, use a self defined function which forces the exact output

Peter Perkins
Peter Perkins on 27 Jul 2021
In the doc for retime (admittedly, not really in flashing bold letters): "All the listed methods omit NaNs, NaTs, and other missing data indicators, except for func. To include missing data indicators, specify func as a function handle to a function that includes them when aggregating data."
Haven't tried it, but I believe that if you pass in @sum, not 'sum', you will get what you want.




Community Treasure Hunt

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

Start Hunting!

Translated by