필터 지우기
필터 지우기

Modifying cell arrays (mixed - string & numeric)

조회 수: 1 (최근 30일)
susan
susan 2012년 10월 22일
I have a cell array 1159x2.. Column 1 is numeric. Column 2 is string..
[645836] 'TSTRCo23_b3_c' [646153] 'Co23_b3_c' [646449] 'RTCo23_b3_c' [646655] 'TEND_b3_c' [646157] 'Co01_b2_ic' [646678] 'Co06_b3_c' ....
I need to modify this to
[646153] 'C23c' [646157] 'C01i' [646678] 'C06c' ....
i.e. Only keep rows where the string starts with Co. BUT, replace the string 1) with C, 2) then the numeric value that follows Co, 3) then either c or i depending on whether the original string was appended with c or ic.
Thank you..
S

답변 (1개)

Matt J
Matt J 2012년 10월 22일
편집: Matt J 2012년 10월 22일
Well, the first step would be to get rid of the unwanted rows. That you can do easily enough by
keeprows=~cellfun('isempty', strfind(cellarray(:,2),'Co') );
cellarray=cellarray(keeprows,:);
Then you just have to go through what's left and modify the strings. Should be easy enough using REGEXPREP and/or STRREP

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by