Info

This question is closed. Reopen it to edit or answer.

selection files from part of his name

1 view (last 30 days)
MB2010
MB2010 on 20 Feb 2020
Closed: MATLAB Answer Bot on 20 Aug 2021
I have a list with the name of several files. I woudl like to selection all the files that contain a certain characters like 3pi2 or 5pi2
List.name
'Box_36_alfa=3pi2_super-arxiv-1023412_fx.txt'
'Box_37_alfa=3pi2_super-arxiv-5612352_fx.txt'
'Box_38_alfa=5pi2_super-arxiv-3567120_fx.txt'
'Box_38_alfa=5pi2_super-arxiv-856132_fx.txt'
i have tried use strfind(List.name,'3pi2?','match'), but does not work

Answers (1)

Guillaume
Guillaume on 20 Feb 2020
Edited: Guillaume on 20 Feb 2020
Patterns for strfind and its recommended replacement contains don't support wildcard characters such as * and ?. In any case, there's no 'match' option for strfind. It looks like you mixed the syntax for regexp with the syntax for strfind.
regexp would indeed solve your problem. However, note that ? in a regular expression doesn't mean match any character. It means match the previous character 0 or 1 time. A valid regular expression for what you want:
~cellfun(@isempty, regexp(List.Name, '(3|5)pi2', 'once')
This will return a logical vector indicated which elements of List.Name match the pattern.

Community Treasure Hunt

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

Start Hunting!