Detecting and eliminating numbers from a cell matrix that contains NaNs and string characters

3 次查看(过去 30 天)
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

采纳的回答

Andrei Bobrov
Andrei Bobrov 2012-7-2
编辑:Andrei Bobrov 2012-7-2
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};

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Operators and Elementary Operations 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by