MATLAB: Loop through file names and load data

.dat filefor loopload

Hello
I have more than 50 dat files with a filenames that vary according to the parameters specified.
Example: 'Au_L707,22,20,5_Gp0_RS1,2,1_P2mesy(xf,yf).dat'
'Au_L707,22,20,5_Gp1_RS3,2,1_P2mesy(xf,yf).dat'
I would like to loop through the 3 parameter values after RS 'RS3,2,1'. Is there a way to selectively loop through the parameters and load the file?
I would like to have control over which parameters I want to loop through among the three. Any leads would be appreciated

Best Answer

You can use compose to create filenames and then iterate over them
params = [1 2 3; % parameter combinations to load.
3 2 1;
5 3 2;
1 2 4];
filenames = compose('Au_L707,22,20,5_Gp1_RS%d,%d,%d_P2mesy(xf,yf).dat', params);
data = cell(size(filenames));
for i = 1:numel(filenames)
data{i} = load(filenames{i});
end