MATLAB: How to delete certain rows that contain string

delete row

I have the following strings within matrix m:
'batch_167_indication_A12-1_replicate_1' 'batch_167_indication_A12-1_replicate_2' 'batch_167_indication_ABC_replicate_3' 'batch_167_indication_ABC_replicate_1' 'batch_167_indication_DEF_replicate_1' 'batch_167_indication_DEF-1_replicate_1'
I only want the output to print:
'batch_167_indication_ABC_replicate_3' 'batch_167_indication_ABC_replicate_1' 'batch_167_indication_DEF_replicate_1' 'batch_167_indication_DEF-1_replicate_1'

Best Answer

So you want to delete any string that contains the string 'A12-1'? Or is it more general than that? Assuming it's just that one string, try this:
C = {'batch_167_indication_A12-1_replicate_1' 'batch_167_indication_A12-1_replicate_2' 'batch_167_indication_ABC_replicate_3' 'batch_167_indication_ABC_replicate_1' 'batch_167_indication_DEF_replicate_1' 'batch_167_indication_DEF-1_replicate_1'}; % cell array of strings
Cnew = C(cellfun(@(s)isempty(regexp(s,'A12-1')),C));
If C isn't a cell array:
C = char('batch_167_indication_A12-1_replicate_1','batch_167_indication_A12-1_replicate_2','batch_167_indication_ABC_replicate_3','batch_167_indication_ABC_replicate_1','batch_167_indication_DEF_replicate_1','batch_167_indication_DEF-1_replicate_1') %character array
Cnew = C(arrayfun(@(i)isempty(regexp(C(i,:),'A12-1')),1:size(C,1)),:);