matlab - Deleting rows with specific rules -
i got 20*3 cell array , need delete rows contains "137", "2" , "n:t"
origin data:
't' '' '' 'np(*)' '' '' [ 137] '' '' [ 2] '' '' 'are' 'and' 'np(fcc_a1#1)' '' '' '1:t' [ 1200] [0.7052] '' [1.2051e+03] [0.7076] '' 'are' 'and' 'np(fcc_a1#3)' '' '' '2:t' [ 1200] [0.0673] '' [1.2051e+03] [0.0671] '' 'are' 'and' 'np(m23c6)' '' '' '3:t' [ 1200] [0.2275] '' [1.2051e+03] [0.2253] '' [ 137] '' '' [ 2] '' ''
and want like
't' '' '' 'np(*)' '' '' 'are' 'and' 'np(fcc_a1#1)' [ 1200] [0.7052] '' [1.2051e+03] [0.7076] '' 'are' 'and' 'np(fcc_a1#3)' [ 1200] [0.0673] '' [1.2051e+03] [0.0671] '' 'are' 'and' 'np(m23c6)' [ 1200] [0.2275] '' [1.2051e+03] [0.2253] ''
i've tried regexp , strcmp , don't work well. plus cell array hard deal with. can help?
thank in advance.
if can somehow read original data cells strings or empty arrays (not numeric values), can strcmp
, regexprep
:
% variable 'data' 2d-cell array of strings or empty arrays datarep = regexprep(data,'^\d+:t','2'); % replace 'n:t' '2' convenience remove1 = strcmp('2',datarep); % takes care of '2' , 'n:t' remove2 = strcmp('137',datarep); % takes care of '137' rows_keep = find(~sum(remove1|remove2,2)); % rows kept solution = data(rows_keep,:)
for example, data
'aa' 'bb' 'cc' 'dd' 'dd' '2' '137' 'dd' 'dd' 'dd' 'dd' '11:t' '1:t' '1:137' 'dd' 'dd' '' []
the result in variable solution
is
'aa' 'bb' 'cc' 'dd' '' []
Comments
Post a Comment