Detecting NaN in cell array

74 visualizzazioni (ultimi 30 giorni)
SG
SG il 26 Mag 2015
Modificato: beginner94 il 18 Dic 2018
I have a 54x8 cell array that contains only strings. Most of these strings represent numbers and I would like to detect which cells are NaN.
One possibility would simply be to replace all NaN with ' ' or to check whether each d{i,j} == NaN.
Thanks

Risposta accettata

Walter Roberson
Walter Roberson il 26 Mag 2015
cellfun(@(C) any(isnan(C(:)), YourCell)
However in your situation you could probably go with
cellfun(@isnumeric, C)
Oh wait, when you say NaN, do you mean the string 'NaN' ? If so then
cellfun(@(C) strcmp(C, 'NaN'), C)
  6 Commenti
Walter Roberson
Walter Roberson il 8 Lug 2017
G H are you comparing numeric nan or string 'NaN'
beginner94
beginner94 il 18 Dic 2018
Modificato: beginner94 il 18 Dic 2018
Hello,
@WalterRoberson:
Is there a way to use this
cellfun(@(ds) strcmp(ds, 'NaN'), ds))
when the cell elements are not aligned but below each other?
Thank you!

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Characters and Strings in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by