Using omitnan in accumarray

21 views (last 30 days)
Michael Mueller
Michael Mueller on 29 Jan 2019
Commented: Michael Mueller on 29 Jan 2019
I am writing a fuction to resize a timetable by a predetermined duration average. For instance the input is time_average(TT,hours(1)); would output an hourly average. The issue is I have some NaN values so when I use accumarray(x,y,[N'1],@mean) I get a series of mostly NaN values. I cannot use nanmean because I do not have access to its toolbox. I know the mean function can be used to omit nan values with mean(X,'omitnan'), but how can I incorporate that in the accumarray function?

Accepted Answer

Rik
Rik on 29 Jan 2019
You can either write a wrapper function, or extend the anonymous function:
accumarray(x,y,[N'1],@(x)mean(x,'omitnan'))
or
accumarray(x,y,[N'1],@my_mean_omitnan)
function res=my_mean_omitnan(in)
res=mean(in,'omitnan');
end
  1 Comment
Michael Mueller
Michael Mueller on 29 Jan 2019
Thank you very much that worked perfectly!

Sign in to comment.

More Answers (0)

Categories

Find more on Tables in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!