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!