MATLAB: File names with a shared beginning

file names

I have different files in a folder, but I want to select files such as 1_1_11.ev2, 1_2_13.ev2, with this common part "strcat(num2str(p),'_')". What should I write instead of the blank in the 3rd line after the "folderName"?
for p =1:length(directoryNames)
folderName = directoryNames{p};
Files = dir(strcat(folderName, ... ));
end

Best Answer

You could try something like this:
for p =1:length(directoryNames)
folderName = directoryNames{p};
filePattern = fullfile(folderName, '*.ev2');
for k = 1 : length(filePattern)
thisFileName = filePattern(k).name;
if UseThisFile(thisFileName)
% Do something with it.
end
end
end
You would write a function called UseThisFile() that determines if the file is one you want to use or not based on the characters between the underlines. So that function would parse the filename and determine if it's OK to use or not and return true or false, respectively.