how to remove NaN
12 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaire
Kye Taylor
le 12 Juin 2013
Modifié(e) : Kye Taylor
le 12 Juin 2013
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?
Réponses (2)
Kye Taylor
le 12 Juin 2013
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,:) = [];
0 commentaires
Andrei Bobrov
le 12 Juin 2013
M = {3 [4 5] nan;[2 4] 'dfgh' [7 8 3]};
ii = ~cellfun(@(x)all(isnan(x(:))),z(:,3));
out = M(ii,:);
0 commentaires
Voir également
Catégories
En savoir plus sur NaNs dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!