Moving mean/std based on number of NaN
조회 수: 2 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
채택된 답변
추가 답변 (1개)
Walter Roberson
2021년 8월 28일
A=[4, 8,6,3,NaN,NaN,-1,9,4,5]'
window = 4;
M=movstd(A,window,'omitnan','Endpoints','discard')
An = isnan(A.');
starts = strfind([false, An], [false,true,true])
stops = strfind([An,false], [true,true,false])+1
M(unique(cell2mat(arrayfun(@(start,stop) start-window+2:stop-1, starts, stops, 'uniform', 0)))) = nan
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 NaNs에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!