Filter löschen
Filter löschen

Remove rows from cell Array which have string in the first column

1 Ansicht (letzte 30 Tage)
rhai123
rhai123 am 28 Jul. 2017
Bearbeitet: Andrei Bobrov am 28 Jul. 2017
I have a cell array of the following format:
M=['test' '12' '122' '...'
'test2' '123' '234' []
'1234' 'RR' '123' []
'test4' '123' '234' []
'2341' 'KK' 's' []
'1121' 'pp' [] []
'tesst3' '12' '122' '...'
]
I want to remove all rows that have a string which is not a number in the first column. The result array is:
result=[
'1234' 'RR' '123' []
'2341' 'KK' 's' []
'1121' 'pp' [] []
]

Antworten (1)

Andrei Bobrov
Andrei Bobrov am 28 Jul. 2017
Bearbeitet: Andrei Bobrov am 28 Jul. 2017
M={'test' '12' '122' '...'
'test2' '123' '234' []
'1234' 'RR' '123' []
'test4' '123' '234' []
'2341' 'KK' 's' []
'1121' 'pp' [] []
'tesst3' '12' '122' '...'}
result = M(~cellfun('isempty',regexp(M(:,1),'^\d+$')),:)
or
result = M(~isnan(str2double(M(:,1))),:)

Kategorien

Mehr zu Cell Arrays finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by