MATLAB: How do you remove specific rows from a cell array

arrays array specific certain cell arrayMATLAB

I have this 70×1 cell that is made up of my files and looks like this:
{'myPC\Documents\MATLAB\DataAnalysis\temp\6\Temp-20\TS1.csv' }
{'myPC\Documents\MATLAB\DataAnalysis\temp\6\Temp-20\TS1.csv' }
{'myPC\Documents\MATLAB\DataAnalysis\temp\6\Temp-20\TS6.csv' }
{'myPC\Documents\MATLAB\DataAnalysis\temp\6\Temp0\Print.csv' }
{'myPC\Documents\MATLAB\DataAnalysis\temp\6\Temp0\TS12.csv' }
{'myPC\Documents\MATLAB\DataAnalysis\temp\6\TS15.csv' }
.
.
.
.
The thing is I want to remove each row that has TS1 in their name, any help? Thanks

Best Answer

  • One approach:
    C = {{'myPC\Documents\MATLAB\DataAnalysis\temp\6\Temp-20\TS1.csv' }
    {'myPC\Documents\MATLAB\DataAnalysis\temp\6\Temp-20\TS1.csv' }
    {'myPC\Documents\MATLAB\DataAnalysis\temp\6\Temp-20\TS6.csv' }
    {'myPC\Documents\MATLAB\DataAnalysis\temp\6\Temp0\Print.csv' }
    {'myPC\Documents\MATLAB\DataAnalysis\temp\6\Temp0\TS12.csv' }
    {'myPC\Documents\MATLAB\DataAnalysis\temp\6\TS15.csv' }};
    r = cellfun(@(x)strfind(x, 'TS1.'), C);
    er = cellfun(@isempty,r);
    Cnew = C(er,:)
    This takes advantage of ‘TS1’ always being followed by ‘.’. It will fail otherwise.