フィルターのクリア

Run a script file multiple times and save variable values to array

4 ビュー (過去 30 日間)
Evan Scope Crafts
Evan Scope Crafts 2019 年 2 月 27 日
コメント済み: Jan 2019 年 2 月 28 日
I have a script file that I would like to run 50 times. Each time the script file is executed I would like certain variables generated by the script file to be saved in an array I have created in the driver file. I have tried creating a driver file with a for loop and using the control variable for the for loop to index the array entries, but Matlab seems to not let me access the control variable (or any other variables in the driver file). Is there an easy way to do this? I am familiar with diary but the text output is tedious to manually convert to an array.

回答 (1 件)

Jan
Jan 2019 年 2 月 27 日
What is a "driver file"? "Matlab seems to not let me access the control variable" - what does this mean? What do you observe? Which code do you try?
It is easy actually:
% YourScript.m
% Your script (prefer functions for a clean programming style!)
a = rand
and the main function for the loop:
function yourLoop
result = zeros(1, 50);
for k = 1:50
run('YourScript')
result(k) = a;
end
end
  5 件のコメント
Evan Scope Crafts
Evan Scope Crafts 2019 年 2 月 28 日
Wow can't believe I didn't catch that. Thanks for helping an undergraduate out
Jan
Jan 2019 年 2 月 28 日
@Evan: clear is rarely useful in Matlab, but it causes troubles frequently.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeDebugging and Analysis についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by