Error using eval when load many files in recursive

23 views (last 30 days)
I want to load many files, i.e.
load('SST_mw_region6.mat','sst','time','lon','lat');
where "6" can be vary from 1 to 20
I did try using :
for k=1:20
eval(['load SST_mw_region' num2str(k) '.mat','sst','time','lon','lat';'])
end
I am not sure where I have to put ' ' and how many of them
Thanks
Dwi

Answers (1)

Walter Roberson
Walter Roberson on 20 Sep 2019
Don't use eval(). Construct your filenames using sprintf() and use the function form of load instead of the command form.
Note that when you do not assign the output of load() to a variable, that each iteration each of the variables you just loaded will be overwritten completely with the variables you just loaded.
  4 Comments
DwiNY
DwiNY on 20 Sep 2019
Dear Walter, Stephen and Guillaume,
Thank you so much for your kind help
Dwi

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!