I want to load multiple .mat files (around 500 in number) into my workspace. The files are named as
omni_AP1_trial_1_loc_1.mat
omni_AP1_trial_1_loc_2.mat
omni_AP1_trial_1_loc_3.mat
.
.
omni_AP1_trial_1_loc_57.mat
.
.
omni_AP1_trial_10_loc_1.mat
omni_AP1_trial_10_loc_2.mat
omni_AP1_trial_10_loc_3.mat
.
.
omni_AP1_trial_10_loc_57.mat
I am using the given code :
files_1 = dir('omni_AP1_trial_*_loc_1.mat');
NumberOfDataset = length(files_1);
for i = 1:NumberOfDataset
%get allfiles matching the pattern 'dataset(i)_*'
files = dir(sprintf('omni_AP1_trial_%d_loc_*.mat',i));
for j = 1:length(files)
fprintf('Current file : %s\n',files(j).name)
a= load(files(j).name);
end
end
During execution even though the fprintf statement shows consecutive files being picked, but the structure a holds only the last file that was picked up and the previous file is being overwritten when the loop iterates.
How can I have all the files loaded together in the workspace ? Please help.