For loop to perform multiple model simulations, error avoidance through try/catch
1 回表示 (過去 30 日間)
古いコメントを表示
Hi.
I'm performing the tuning of some parameters in my simulink model, by using a for loop and simulating for each set of parameters.
When the system is unstable, the simulation ends before the stop time, causing an error.
To skip the error message, I used try/catch:
...
try
out = sim("model.slx");
catch
end
...
However, one important information for me is how far the simulation progresses for each set of parameters. The try/catch block does not save the "out" variable in the presence of an error, meaning that "out.tout" is not updated for each simulation.
How can I keep running the for loop, skip errors and update the out variable?
Are there any alternatives to try/catch for my specific case?
0 件のコメント
採用された回答
Harsh Saxena
2023 年 7 月 17 日
Hi Vita,
You can use the try/catch statement like this:
try
out = sim("model.slx");
catch ME
disp(ME);
out = ME;
end
Using this you will be able to see the error message corresponding to every simulation as well as store it in out as well. I would recommend storing it like:
catch ME
disp(ME);
out = [out;ME];
end
to store all the error messages and not overwrite any one of them.
Hope this helps!
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!