how to remove NaN

조회 수: 5 (최근 30일)
andrew
andrew 2013년 6월 12일
I have a m x n cell array. I want to search the 6th column for Nan cells and delete the entire row with the NaN cell.
tried: M( all( isnan( M ), 2 ), : ) = []; but get the following error: Undefined function 'isnan' for input arguments of type 'cell'.
  댓글 수: 1
Kye Taylor
Kye Taylor 2013년 6월 12일
편집: Kye Taylor 2013년 6월 12일
Although this command is causing the error
M( all( isnan( M ), 2 ), : ) = [];
it appears that you're trying to delete rows where all entries are NaNs. But you say you want to delete rows that contain a NaN in the sixth column. Which is it?

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

답변 (2개)

Kye Taylor
Kye Taylor 2013년 6월 12일
You're very close try
% idx(i) is true if contents in row i, column 6 of M equals NaN
idx = cellfun(@isnan,M(:,6))
% delete row with nan in it
M(idx,:) = [];

Andrei Bobrov
Andrei Bobrov 2013년 6월 12일
M = {3 [4 5] nan;[2 4] 'dfgh' [7 8 3]};
ii = ~cellfun(@(x)all(isnan(x(:))),z(:,3));
out = M(ii,:);

카테고리

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