Standard Deviation of 3D matrix with NaN elements

조회 수: 4 (최근 30일)
António Rouxinol Fragoso
António Rouxinol Fragoso 2019년 9월 17일
댓글: Rik 2019년 9월 17일
I have a 3D matrix of size (170 x 170 x 27). Some of the entries are NaN, zero and the rest have real values.
I would like to obtain the standard deviation of this matrix, excluding the NaNs. I have tryed several commands, but I haven't been able to get this to work.
Could you help me?
Thank you in advance,
Antonio :)

답변 (2개)

Johannes Fischer
Johannes Fischer 2019년 9월 17일
As described in the doumentation for std, there is a flag on how to deal with 'NaN' values. If you want the standard deviation of all values, excluding the NaNs, then write
% dummy matrix
m=rand(170, 170, 27);
m(m>0.9) = NaN;
sdev = std(m, 0, 'all', 'omitnan')
  댓글 수: 4
António Rouxinol Fragoso
António Rouxinol Fragoso 2019년 9월 17일
I'm using R2018a.
Rik
Rik 2019년 9월 17일
The 'all' syntax was introduced in R2018b, so you'll have to linearize your array like I describe in my answer. doc for R2018a, doc for R2018b

댓글을 달려면 로그인하십시오.


Rik
Rik 2019년 9월 17일
This syntax should work for most releases:
sdev=std(m(:),'omitnan');

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by