How to ask matlab to find mean only if there are less than 3 NaN values?

조회 수: 1 (최근 30일)
MP
MP 2022년 8월 5일
댓글: MP 2022년 8월 5일
How to ask matlab to find mean only if there are less than 2 NaN values in a given column, otherwise it should be NaN?
For Example,
qq = [1 2 3 NaN; 1 NaN NaN NaN];
qqm = mean(qq','omitnan');
qqm
% o/p is Value: [2,1], size: 1x2, Class: Double
I want to find output like:
qqm = [2, NaN]
Any help will be greatly appriciated.

채택된 답변

Bruno Luong
Bruno Luong 2022년 8월 5일
qq = [1 2 3 NaN; 1 NaN NaN NaN];
qqm = mean(qq','omitnan');
qqm(sum(isnan(qq),2)>=2) = NaN;
qqm
qqm = 1×2
2 NaN

추가 답변 (0개)

카테고리

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