How to find NaN values in a cell array.

22 vues (au cours des 30 derniers jours)
Thirunavukkarasu Yadav
Thirunavukkarasu Yadav le 30 Déc 2016
Commenté : Image Analyst le 8 Juil 2017
This is my data:
a = {'raja' 'I' 76 56 NaN;'bala' 'R' 12 7 56;'kavi' NaN 56 5 12}
X = find(isnan(a));
I got
??? undefined function or method 'isnan'
for input arguments of type 'cell'.

Réponse acceptée

Image Analyst
Image Analyst le 30 Déc 2016
Try this to examine columns 2 onwards:
a = {'raja' 'I' 76 56 NaN;'bala' 'R' 12 7 56;'kavi' NaN 56 5 12}
b = cell2mat(cellfun(@isnan, a(:, 2:end), 'UniformOutput', false))
You'll see:
a =
3×5 cell array
'raja' 'I' [76] [56] [NaN]
'bala' 'R' [12] [ 7] [ 56]
'kavi' [NaN] [56] [ 5] [ 12]
b =
3×4 logical array
0 0 0 1
0 0 0 0
1 0 0 0
  3 commentaires
G H
G H le 8 Juil 2017
Why should we strart from the second line? "a(:, 2:end)"
Image Analyst
Image Analyst le 8 Juil 2017
Well, you can start from the first column (not line as you said), if you want to check the names for nans.

Connectez-vous pour commenter.

Plus de réponses (1)

the cyclist
the cyclist le 30 Déc 2016
Modifié(e) : the cyclist le 30 Déc 2016
Here is one way:
find(cell2mat(cellfun(@(x)any(isnan(x)),a,'UniformOutput',false)))
I had to stick the "any" command in there to deal with the strings, but I think this still does what you intend.

Community Treasure Hunt

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

Start Hunting!

Translated by