For loop to perform multiple model simulations, error avoidance through try/catch
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Vita Glielmi
le 15 Juil 2023
Commenté : Vita Glielmi
le 20 Juil 2023
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 commentaires
Réponse acceptée
Harsh Saxena
le 17 Juil 2023
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!
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!