Delete rows in cell that contain part of string

조회 수: 28 (최근 30일)
newbie9
newbie9 2019년 3월 13일
댓글: newbie9 2019년 3월 13일
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));

채택된 답변

madhan ravi
madhan ravi 2019년 3월 13일
편집: madhan ravi 2019년 3월 13일
Cell(strcmp(Cell(:,1),'>'),:)=[]

추가 답변 (1개)

newbie9
newbie9 2019년 3월 13일
편집: newbie9 2019년 3월 13일
Below works, but perhaps is not the most elegant code.
rawdata = textscan(fid, '%s %s' , 'HeaderLines', 7);
fclose all;
rawdata = [rawdata{:}];
idx = strfind(rawdata(:,1),'>');
tf = cellfun('isempty', idx);
tf = [tf tf];
data1 = rawdata(tf);
data1 = reshape(data1,[length(data1)/2, 2]);

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by