Error using eval when load many files in recursive

23 views (last 30 days)
I want to load many files, i.e.
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';'])
I am not sure where I have to put ' ' and how many of them

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.
DwiNY on 20 Sep 2019
Dear Walter, Stephen and Guillaume,
Thank you so much for your kind help

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!