For loop to perform multiple model simulations, error avoidance through try/catch
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Vita Glielmi
el 15 de Jul. de 2023
Comentada: Vita Glielmi
el 20 de Jul. de 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 comentarios
Respuesta aceptada
Harsh Saxena
el 17 de Jul. de 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!
Más respuestas (0)
Ver también
Categorías
Más información sobre Loops and Conditional Statements en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!