필터 지우기
필터 지우기

find the cell array contains a specific string

조회 수: 140 (최근 30일)
Yu Li
Yu Li 2018년 11월 28일
편집: Stephen23 2018년 11월 28일
I have a cell array as attached, I want to find the row number which contains a specified string, such as 'bore', I know how to write a for-loop to compare the element one by one, but, is there any easier way to do this?
Thanks!
Yu

채택된 답변

Stephen23
Stephen23 2018년 11월 28일
편집: Stephen23 2018년 11월 28일
Use strfind:
>> idc = strfind(file,'bore'); % search for 'bore' in all cells.
>> idx = ~cellfun('isempty',idc) % logical index, which cells contain 'bore'.
idx =
1
0
0
0
0
0
0
0
0
0
0
0
We can clearly see that the string in the first cell contains the pattern 'bore'. The indices in the cell array idc tell you where in the string/s that pattern was found.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Cell Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by