find nan and eliminate it in matrix
75 views (last 30 days)
the cyclist on 18 Nov 2012
Edited: the cyclist on 19 Nov 2012
The reason that a vector rather than a matrix is returned is that MATLAB doesn't know that your "mask" is going to still be rectangular. For example, if your input had been
A = [1 2; 3 NaN];
then your code wouldn't be able to return a matrix.
As Walter's question suggests, you'll need to decide what to do about partial-NaN rows. Probably one of the following is what you want:
% Remove rows with all NaN:
A(all(isnan(A),2),:) = 
% Remove row with any NaN:
A(any(isnan(A),2),:) = 
You could do the analogous operations on columns by changing the 2's to 1's (and using the semicolon in the first index instead of the second).
More Answers (1)
Walter Roberson on 18 Nov 2012
What do you want to have happen if the rows contain unequal number of nans? Do you want to delete the entire row if any member of the row contains a nan? Or only delete the row if it is all nan?