Using omitnan in accumarray

20 ビュー (過去 30 日間)
Michael Mueller
Michael Mueller 2019 年 1 月 29 日
コメント済み: Michael Mueller 2019 年 1 月 29 日
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?

採用された回答

Rik
Rik 2019 年 1 月 29 日
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 件のコメント
Michael Mueller
Michael Mueller 2019 年 1 月 29 日
Thank you very much that worked perfectly!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeTables についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by