I want load many files from a directory that their names have a pattern such as: data_1 & data_2 , ... , that as mentioned, the numbers in each "data_" are as the same with the counter of the main for loop.
How can I do this for matching the file names that are loading with the number of counter of the for loop. This is my imperfect code:
for i=1:100
loadpath='./folder/data/';
load('Label_i.mat');
end
load(['Label_' num2str(i) '.mat']); Beside, what's the purpose of havingloadpath='./folder/data/';in each iteration if it do not change and it is not used?sprintfwith the%iformat spec:load(sprintf('Label_%i.mat', i));load(sprintf('./folder/data/Label_%i.mat', i));or usefullfile:load(fullfile(loadpath, sprintf('Label_%i.mat', i)));