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

조회 수: 2 (최근 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