Delete rows in cell that contain part of string
조회 수: 18 (최근 30일)
이전 댓글 표시
I have an Nx2 cell (mixes of strings and doubles) that I'm trying to clean up (rawdata). Specifically, I am trying to delete all rows with ">" in the first column. My code below is deleting those rows, but it is reshaping the cell as an Mx1 cell (data1). I'm not sure where the error is. Thanks for any help.
rawdata = textscan(fid, '%s %s' , 'HeaderLines', 7);
rawdata = [rawdata{:}];
data1 = rawdata(cellfun(@(s)isempty(regexp(s,'>')),rawdata));
댓글 수: 0
채택된 답변
madhan ravi
2019년 3월 13일
편집: madhan ravi
2019년 3월 13일
Cell(strcmp(Cell(:,1),'>'),:)=[]
댓글 수: 3
Image Analyst
2024년 7월 17일
Example with 2-by-2 cell array:
Cell = { '>', 123, 'abc', 'xyz'; '2abc', 456, '>' 'str'}
Cell(strcmp(Cell(:,1),'>'),:)=[]
Note that row 1 is gone because the first cell in that row is '>'.
Not sure how certain you are that the > contains no white space but you may make it more robust by using strtrim and/or startsWith, for example if the > was the first non-white character and had other characters after it, you could do it this way:
Cell = { ' > ', 123, 'abc', 'xyz'; '2abc', 456, '>' 'str'}
Cell(startsWith(strtrim(Cell(:,1)),'>'),:)=[]
추가 답변 (1개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Cell Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!