Saving multiple files using for loop
41 views (last 30 days)
I have 36 scripts representing 36 housess.
Each script has an output G. What I want is to save G in G1, G2... G36. Like:
save ( 'Gi.mat','G') %save ( 'G1.mat','G'), save ( 'G2.mat','G')...save ( 'G36.mat','G')
So what I want is to be able to save 36 different files in one run, is that possible?.
Sajid Afaque on 2 Apr 2021
Edited: Sajid Afaque on 2 Apr 2021
if you are running the 36 different scripts individually then you have to use a for loop.
this way your code would be shorter
for i = 1 : 36
run ['H' num2str(i)]
output_name = ['G' num2str(i) '.mat']
or else if you want all to run at one go you have to write a lengthy code
save ( 'G1.mat','G') ;
save ( 'G2.mat','G') ;
save ( 'G3.mat','G') ;
save ( 'G36.mat','G') ;