Removing elements of a cell array that start with a specific letter

조회 수: 29 (최근 30일)
Josh Tome
Josh Tome 2022년 12월 14일
편집: Stephen23 2022년 12월 14일
I have a cell array of strings which I would like to remove the elements which start with an uppercase R. What is the easiest way to do this?

채택된 답변

Stephen23
Stephen23 2022년 12월 14일
편집: Stephen23 2022년 12월 14일
"What is the easiest way to do this?"
Where C is your cell array:
X = startsWith(C,'R');
C(X) = []

추가 답변 (1개)

Image Analyst
Image Analyst 2022년 12월 14일
Unfortunately you didn't read the posting guidelines and therefore forgot to attach your data. But I'll take a stab at it with no data.
numCells = numel(ExpModOutVariables);
indexesToDelete = false(numCells, 1);
for k = 1 : numCells
thisCell = ExpModOutVariables{k};
if startsWith(thisCell, 'R')
indexesToDelete(k) = true;
end
end
% Do the deletion
ExpModOutVariables(indexesToDelete) = [];
If you have any more questions, then attach your data and code to read it in with the paperclip icon after you read this:

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by