Moving mean/std based on number of NaN

4 ビュー (過去 30 日間)
Dave
Dave 2021 年 8 月 28 日
回答済み: Walter Roberson 2021 年 8 月 28 日
Hello,
Is there a way to compute movstd but replace with NaN if the window includes 2 or more NaN?
A=[4, 8,6,3,NaN,NaN,-1,9,4,5]'
This window is 4
M=movstd(A,4,'omitnan','Endpoints','discard')
M is
2.217355783
2.516611478
2.121320344
2.828427125
7.071067812
5
4.11298756
With the condition to replace with NaN if the window includes 2 or more NaN
M should be
2.217355783
2.516611478
NaN
NaN
NaN
5
4.11298756

採用された回答

Matt J
Matt J 2021 年 8 月 28 日
編集済み: Matt J 2021 年 8 月 28 日
A=[4, 8,6,3,NaN,NaN,-1,9,4,5]';
M=movstd(A,4,'omitnan','Endpoints','discard');
idx=movsum(isnan(A),4,'omitnan','Endpoints','discard')>=2;
M(idx)=nan
M = 7×1
2.2174 2.5166 NaN NaN NaN 5.0000 4.1130
  1 件のコメント
Dave
Dave 2021 年 8 月 28 日
Danke

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

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2021 年 8 月 28 日
A=[4, 8,6,3,NaN,NaN,-1,9,4,5]'
A = 10×1
4 8 6 3 NaN NaN -1 9 4 5
window = 4;
M=movstd(A,window,'omitnan','Endpoints','discard')
M = 7×1
2.2174 2.5166 2.1213 2.8284 7.0711 5.0000 4.1130
An = isnan(A.');
starts = strfind([false, An], [false,true,true])
starts = 5
stops = strfind([An,false], [true,true,false])+1
stops = 6
M(unique(cell2mat(arrayfun(@(start,stop) start-window+2:stop-1, starts, stops, 'uniform', 0)))) = nan
M = 7×1
2.2174 2.5166 NaN NaN NaN 5.0000 4.1130

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by