- Use regexp (unfortunately here I can't help, I've never really understood regular expressions)
- You can do partial comparison:
How can I use strcmp (or something else) to compare to multiple strings at once?
조회 수: 55 (최근 30일)
이전 댓글 표시
I want to compare all the strings in a cell (messages) to a list of string and return true if it matches any of them.
It should match the function of:
trialSplitPoints = find(strcmp('TRIALID 1',messages));
but for 'TRIALID 1' through 'TRIALID 8'.
댓글 수: 0
채택된 답변
Titus Edelhofer
2015년 9월 18일
Hi,
apart from Walter's method there are two additional:
trialSplitPoints = find(strncmp(messages, 'TRIALID', length('TRIALID')));
Note, it's strncmp, not strcmp.
Titus
댓글 수: 0
추가 답변 (1개)
Walter Roberson
2015년 9월 18일
tf = ismember(messages, {'TRIALID 1', 'TRIALID 2', 'TRIALID 3', ... 'TRIALID 8'})
tf will be an array the same shape as "messages", indicating for each cell array element whether it matches any of the listed items.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Characters and Strings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!