- 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?
65 次查看(过去 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!