matlab - Loading multiple .mat files in the workspace -


i want load multiple .mat files (around 500 in number) workspace. files named

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 using given code :

files_1 = dir('omni_ap1_trial_*_loc_1.mat'); numberofdataset = length(files_1);  = 1:numberofdataset       %get allfiles matching pattern 'dataset(i)_*'     files = dir(sprintf('omni_ap1_trial_%d_loc_*.mat',i));     j = 1:length(files)        fprintf('current file : %s\n',files(j).name)        a= load(files(j).name);      end end 

during execution though fprintf statement shows consecutive files being picked, structure a holds last file picked , previous file being overwritten when loop iterates.

how can have files loaded in workspace ? please help.

you can create array of structs results in iteration:

a = []; % create empty array files_1 = dir('omni_ap1_trial_*_loc_1.mat'); numberofdataset = length(files_1);  = 1:numberofdataset       %get allfiles matching pattern 'dataset(i)_*'     files = dir(sprintf('omni_ap1_trial_%d_loc_*.mat',i));     j = 1:length(files)        fprintf('current file : %s\n',files(j).name)         a(end+1)= load(files(j).name); % store data in struct array      end end 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -