Movmean skipping NaN in array
3 ビュー (過去 30 日間)
古いコメントを表示
I have an array
x = [20 10 5 NaN]; %and I now use:
movmean([x; x(1, :)], [0 1], 1, 'omitnan', 'Endpoints', 'discard')
to calculate the mean, [15 7.5 5 20].
I would like to get [15 7.5 12.5 NaN] so skip over NaN and calculate the mean of 20 and 5 as well, instead of having NaN being replaced by 20 after using movmean. What is the best way to do this?
回答 (1 件)
Image Analyst
2022 年 3 月 27 日
Not sure where the 12.5 is coming from but maybe you'd like this:
x = [20, 10, 5, NaN];
kernel = [1,1];
xs = x;
xs(isnan(x)) = 0;
theSum = conv(xs, kernel, 'same')
theCount = conv(~isnan(x), kernel, 'same')
output = theSum ./ theCount
5 件のコメント
Image Analyst
2022 年 3 月 28 日
So now I'm getting confused. Do you have a row vector, or a 2-D matrix? You've shown both.
参考
カテゴリ
Help Center および File Exchange で Matrices and Arrays についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!