Saving multiple files using for loop

13 ビュー (過去 30 日間)
Joel Schelander
Joel Schelander 2021 年 4 月 2 日
コメント済み: Stephen23 2021 年 4 月 2 日
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:
L=1:36;
for i=1:length(L)
if i==1
run 'H1'
end
if i==2
run 'H2'
end
.
.
.
if i==36
run 'H36'
end
save ( 'Gi.mat','G') %save ( 'G1.mat','G'), save ( 'G2.mat','G')...save ( 'G36.mat','G')
end
So what I want is to be able to save 36 different files in one run, is that possible?.

採用された回答

Sajid Afaque
Sajid Afaque 2021 年 4 月 2 日
編集済み: Sajid Afaque 2021 年 4 月 2 日
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']
save (output_name,'G')
end
or else if you want all to run at one go you have to write a lengthy code
run 'H1';
save ( 'G1.mat','G') ;
run 'H2';
save ( 'G2.mat','G') ;
run 'H3';
save ( 'G3.mat','G') ;
.
.
.
.
.
.
run 'H36';
save ( 'G36.mat','G') ;

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by