필터 지우기
필터 지우기

How to count NaN elements in n dimentional matrix, using counter in loop?

조회 수: 33 (최근 30일)
Thara C.S
Thara C.S 2019년 1월 1일
답변: Stephen23 2019년 1월 1일
How to count NaN elements in n dimentional matrix, using counter in loop?

답변 (2개)

madhan ravi
madhan ravi 2019년 1월 1일
편집: madhan ravi 2019년 1월 1일
Without loop:
A=rand(2,2,2); % a short example with 3D matrix
A(2,2,1)=NaN; % just insert nan values to check
A(2,2,2)=NaN;
NaNs_present=nnz(isnan(A))
With loop(not necessary though):
A=rand(2,2,2);
A(2,2,1)=NaN;
A(2,2,2)=NaN;
Result=cell(1,size(A,1));
ctr=1;
for i = 1:size(A,1)
for j = 1:size(A,2)
for k = 1:size(A,3)
Result{ctr}=isnan(A(i,j,k))
ctr=ctr+1;
end
end
end
NaNs_present=nnz([Result{:}])

Stephen23
Stephen23 2019년 1월 1일
Where A is your array:
cnt = 0;
for k = 1:numel(A)
cnt = cnt+isnan(A(k));
end

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by