Find row with NaN in it.

조회 수: 24 (최근 30일)
Artyom
Artyom 2014년 8월 17일
댓글: sworland 2015년 12월 9일
I have variable X.
X=[2 4 6;
4 5 NaN
3 NaN NaN
5 8 12
3 8 NaN];
How to find any row with NaN in it. ismember([3 8 NaN],X,'rows') gives me 0.
  댓글 수: 1
Artyom
Artyom 2014년 8월 17일
I mean how to find specific row in the matrix (for example 'find' [3 8 NaN] must return me [0;0;0;0;1];).

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

채택된 답변

per isakson
per isakson 2014년 8월 17일
편집: per isakson 2014년 8월 17일
A start:
is(:,1) = X(:,1)==3;
is(:,2) = X(:,2)==8;
is(:,3) = isnan( X(:,3));
all( is, 2 )
which returns
ans =
0
0
0
0
1
AFAIK: isnan is the only way to spot NaN.
I don't think there is a magic one-liner. A little function along the example above is one way. Loop over all columns, ....

추가 답변 (3개)

Guillaume
Guillaume 2014년 8월 17일
[rows, columns] = find(isnan(X));
unique(row);
will give you the row indices
  댓글 수: 1
sworland
sworland 2015년 12월 9일
simple and fast, 1 upvote

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


Roger Stafford
Roger Stafford 2014년 8월 17일
편집: Roger Stafford 2014년 8월 17일
The code
t = any(isnan(X),2);
will return you a column vector of logicals in which each element is true if the corresponding row of X contains a NaN. I trust that would meet your needs. In your example you would get t = [false;true;true;false;true].

Andrei Bobrov
Andrei Bobrov 2014년 8월 17일
편집: Andrei Bobrov 2014년 8월 17일
X=[2 4 6;
4 5 NaN
3 NaN NaN
5 8 12
3 8 NaN];
с = [3 8 NaN];
z = [X;c];
z(isnan(z)) = max(z(:)) + 1;
out = ismember(z(1:end-1,:),z(end,:),'rows');
other example
X = randi(100,200,15);
X([5,125],[2,10]) = nan; % your array
c = X(5,:);
z = [X;c];
z(isnan(z)) = max(z(:)) + 1;
out = ismember(z(1:end-1,:),z(end,:),'rows');

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by