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

1 view (last 30 days)
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' [] []
]

Answers (1)

Andrei Bobrov
Andrei Bobrov on 28 Jul 2017
Edited: Andrei Bobrov on 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))),:)

Categories

Find more on Structures 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!