Find row with NaN in it.
Mostra commenti meno recenti
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 Commento
Artyom
il 17 Ago 2014
Risposta accettata
Più risposte (3)
Roger Stafford
il 17 Ago 2014
Modificato: Roger Stafford
il 17 Ago 2014
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
il 17 Ago 2014
Modificato: Andrei Bobrov
il 17 Ago 2014
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');
Categorie
Scopri di più su NaNs in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!