How do I use the "omitnan' option for the Mean function when calling the function using the splitapply function?

I would like to use the following command: splitapply(@mean,MyArray,G) but call the @mean function using the "omitnan" option. How can I do that? In this example, MyArray is the array that I would like to apply the mean function to after I have split it into Groups dictated by the G vector

2 件のコメント

If my Answer helped you solve your problem, please Accept it!

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

 採用された回答

One option:
splitapply(@(x)mean(x,'omitnan'),MyArray,G)

6 件のコメント

If my Answer helped you solve your problem, please Accept it!
How would I use 'omitnan' in this scenario?
varfun(@mean,timetable,'GroupingVariable','Date & Time');
Star Strider
Star Strider 2020 年 12 月 11 日
編集済み: Steven Lord 2020 年 12 月 11 日
Phoebe Armitage —
Probably:
varfun(@(x)mean(x,'omitnan'),timetable,'GroupingVariable','Date & Time');
That should work, although since I didn’t test it, I’m posting it as UNTESTED CODE. (I never tried that with varfun, however I have tried it in similar situations.)
If you have the Statistics and Machine Learning Toolbox, you can use nanmean with only the function handle and not the full anonymous function construction.
[SL: fixed typo Lenaring -> Learning]
Steven — Thank you!
We desperately need spell check on Answers posts!
It does work, thank you!
Phoebe Armitage —
My pleasure!
(A Vote would be appreciated!)

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

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by