Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

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

조회 수: 1 (최근 30일)
Hi,
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;
end
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