Remove rows from cell Array which have string in the first column
1 次查看(过去 30 天)
显示 更早的评论
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' [] []
]
0 个评论
回答(1 个)
Andrei Bobrov
2017-7-28
编辑:Andrei Bobrov
2017-7-28
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))),:)
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Structures 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!