How can I do the implementation doing this in matlab;
ismember(file_names,['*.mp4'])
How can I do the implementation doing this in matlab;
ismember(file_names,['*.mp4'])
I would do that with regexp
, like this:
result = ~cellfun(@isempty,(regexp(file_names,'\.mp4$')));
For example,
file_names = {'aaa.mp4','bbb.mp3'};
gives
result =
1 0
This can be easily achieved with regexp
:
tf = ~cellfun('isempty', regexp(file_names, '.*\.mp4'));
If you want to force the pattern matching to the beginning or the end of the filename, you should add a caret (^
) or a dollar sign ($
) respectively, for instance:
%// Match pattern at the beginning of the filename
tf = ~cellfun('isempty', regexp(file_names, '^.*\.mp4'));
%// Match pattern at the end of the filename
tf = ~cellfun('isempty', regexp(file_names, '\.mp4$'));
If your search pattern is simple enough, you can use strfind
instead:
tf = ~cellfun('isempty', strfind(file_names, '.mp4'));
Note that this method does not allow you to search for more complicated patterns, nor check conditions (trivially) such as the appearance of the pattern at the end of the string...