Detecting and eliminating numbers from a cell matrix that contains NaNs and string characters
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Dear all, I have a cell matrix An example is the following
total(1:20,1:2)
ans =
[ NaN] [ NaN]
[ NaN] [ NaN]
[ NaN] [ NaN]
'England' [ NaN]
[ NaN] [ NaN]
[ NaN] [ NaN]
' AUSTRIA' ' SMOKES'
[1x20 char] 'NIKE'
[1x26 char] [1x46 char]
[1x26 char] [1x41 char]
[1x26 char] [1x38 char]
[1x20 char] 'GOODYS'
[1x26 char] [1x56 char]
[1x26 char] [1x48 char]
[1x26 char] [1x47 char]
' BAND 1' 'HIT'
' BAND 2 KA 1' [1x39 char]
' BAND 2 KA 2' [1x42 char]
' BAND 2 KA 3' [1x47 char]
' BAND 2 KA 4' 'YES'
The problem is that sometimes these 2 columns contain numbers in some cells, like zero, and this distorts the analysis. Is it possible to detect such numbers and if exist eliminate then from the corresponding cells?
thanks
0 commentaires
Réponse acceptée
Andrei Bobrov
le 2 Juil 2012
Modifié(e) : Andrei Bobrov
le 2 Juil 2012
A = {[ NaN] [ NaN]
[ NaN] [ NaN]
[ NaN] [ NaN]
'England' [ NaN]
[ NaN] [ NaN]
[ NaN] [ NaN]
' AUSTRIA' ' SMOKES'
'tetete' 'NIKE'
'jhjh khkhkh' 'GOODYS'
' BAND 1' 'HIT'
' BAND 2 KA 1' 'eerrrr'
' BAND 2 KA 2' 'dddddd'
' BAND 2 KA 3' [ NaN]
' BAND 2 KA 4' 'YES' };
eg
A(cellfun(@(x)isnumeric(x)&~all(isnan(x)),A)) = {NaN};
OR just
A(cellfun(@(x)isnumeric(x),A)) = {NaN};
Plus de réponses (0)
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!