I have a char variable called "condition". The content of this variable is something like: "21331-54-task-5da1-6256853-35-1-3.mp4".
I need to determine which one of the following characters is contained in the name: 25, 35, 45. I tried with contains(), but this only tells me whether one of these is contained or not in condition. It doesn't tell me which one is contained.
I also tried:
strToFind = {'25', '35', '45'};
pos = strfind(strToFind, condition)
but it gives me the following result:
pos =
1×3 cell array
{0×0 double} {0×0 double} {0×0 double}
Any suggestion on how to solve this? Thank you in advance
~cellfun(@isempty, regexp(condition, strToFind, 'once'))
will give a logical array the same size as strToFind
, telling if each of the strings in strToFind
is present in condition
.
You can also use
cellfun(@(x) contains(condition, x), strToFind)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.