How to find a certain string in a cell with variable size
이전 댓글 표시
Suppose we have a varying sized cell array, e.g:
TempCell = {{'a1','a2'},{'a3','a4','a8','a7'},{'a2','a1'},{'a9'}};
Now, how to find indices of a certain string (like 'a1') in TempCell and remove those arrays which contain that specific string?:
TempCell = {{'a3','a4','a8','a7'},{'a9'}};
I assume Cellfund would be of use, but I could not find any efficient way to use it (I mean without any loop). Any help is more than welocme!
채택된 답변
추가 답변 (1개)
Jan
2015년 10월 25일
And the llop method:
pattern = 'a1';
TempCell = {{'a1','a2'},{'a3','a4','a8','a7'},{'a2','a1'},{'a9'}};
remove = false(size(TempCell));
for k = 1:numel(TempCell)
remove = any(strcmp(TempCell{k}, pattern));
end
TempCell(remove) = [];
카테고리
도움말 센터 및 File Exchange에서 Whos에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!