How do you remove specific rows from a cell array?

I have this 70x1 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

 채택된 답변

Star Strider
Star Strider 2019년 6월 21일
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.

댓글 수: 1

I did not get that error with the data you posted, and my code.
Without seeing the rest of your code, (the relevant parts of it anyway), I cannot imagine what the problem could be.
Note that you must put 'UniformOutput' in single quotes in the cellfun function.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

KALYAN ACHARJYA
KALYAN ACHARJYA 2019년 6월 21일
편집: KALYAN ACHARJYA 2019년 6월 21일
How do you remove specific rows from a cell array?
data=num2cell(rand(70,1)); % Considering random cell array
%delete suppose 4 row
data(4,:)=[];
Check sizes
Name Size Bytes Class Attributes
data 70x1 8400 cell
Name Size Bytes Class Attributes
data 69x1 8280 cell

카테고리

도움말 센터File Exchange에서 Data Type Conversion에 대해 자세히 알아보기

제품

질문:

2019년 6월 21일

댓글:

2019년 6월 22일

Community Treasure Hunt

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

Start Hunting!

Translated by