この質問は閉じられています。 編集または回答するには再度開いてください。

Running the files on a sequence, saving the results, running the files again, saving the results with different name

1 回表示 (過去 30 日間)
Alexandra 2016 年 11 月 8 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
I use a .m file with just diary function in it to run several different files sequentially in the same folder. diary log1.txt;file1;clear variables diary log2.txt;file2;clear variables diary log3.txt;file3;clear variables
File 1 ends with: save('result1','variable1','variable2')
File 2 ends with: save('result2','variable3','variable4')
Same reasoning for file 3. How can I run the 3 files 50 times and save the results in different files for each run. Or save in the same file without overwritting, which I think would be more difficult. For example: saving: first run: results1_1 results2_1 results3_1
second run: results1_2 results2_2 results3_2
for 50 runs
Thank you very much.

回答 (1 件)

Jayaram Theegala
Jayaram Theegala 2016 年 11 月 14 日
For creating your "results" files for 50 runs, you can create a for-loop for 50 iterations and the "results1_1", "results2_1", "results3_1" can be created in first iteration and "results1_2", "results2_2", "results3_2" can be created in second iteration and so on.
For creating the file names dynamically, you can create them based on the iteration number. The following MATLAB code can illustrate the above point:
for i = 1:50
diary(['results1_', num2str(i),'.txt']); %dynamically creating the file name
disp('Hello'); %replace this line with the code you are calling
diary off;
The above MATLAB code creates 50 files by names: "results1_1.txt", "results1_2.txt", ... "results1_50.txt". You can add all the files you want to run within the for-loop and those files will be run for 50 times.
Hope this helps.


Community Treasure Hunt

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

Start Hunting!

Translated by