Detecting and eliminating numbers from a cell matrix that contains NaNs and string characters
1 view (last 30 days)
Show older comments
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 Comments
Accepted Answer
Andrei Bobrov
on 2 Jul 2012
Edited: Andrei Bobrov
on 2 Jul 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};
More Answers (0)
See Also
Categories
Find more on NaNs in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!