MATLAB: How can I select .mat file to load from part of the name

loading .mat filesselect file to load from part of its name

I need to load the following files one by one, using a for loop, because at each iteration I have to do some calculation with the variables of these files:
110-1-D2-6-sum.mat
110-1-D3-7-sum.mat
110-1-E0-8-sum.mat
110-1-E0-12-sum.mat
How can I do this? The problem is that the name changes not only in the last number, but also in the letters. I would load them using part of the name (D2-6; D3-7….)

Best Answer

projectdir = pwd; %or appropriate directory name
looking_for = 'D2-6';
dinfo = dir( fullfile(projectdir, ['*' looking_for '*.mat']) );
filenames = fullfile(projectdir, {dinfo.name});
num_files = length(filenames);
results = cell(num_files, 1);
for K = 1 : num_files
this_file = filenames{K};
results{K} = Process_a_file(this_file);
end