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

1 vue (au cours des 30 derniers jours)
rhai123
rhai123 le 28 Juil 2017
Modifié(e) : Andrei Bobrov le 28 Juil 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' [] []
]

Réponses (1)

Andrei Bobrov
Andrei Bobrov le 28 Juil 2017
Modifié(e) : Andrei Bobrov le 28 Juil 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))),:)

Catégories

En savoir plus sur Structures 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!

Translated by