How to count NaN elements in n dimentional matrix, using counter in loop?
33 次查看(过去 30 天)
显示 更早的评论
How to count NaN elements in n dimentional matrix, using counter in loop?
0 个评论
回答(2 个)
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{:}])
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!