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!