Removing elements of a cell array that start with a specific letter
27 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Josh Tome
am 14 Dez. 2022
Bearbeitet: Stephen23
am 14 Dez. 2022
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?
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1231337/image.png)
0 Kommentare
Akzeptierte Antwort
Weitere Antworten (1)
Image Analyst
am 14 Dez. 2022
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:
0 Kommentare
Siehe auch
Kategorien
Mehr zu Data Type Conversion finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!