Set Simulink model simulation stop time from m file
100 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Lucas
el 6 de Jun. de 2012
Comentada: Bill Tubbs
el 15 de Nov. de 2022
I want to set my models simulation stop time from an m file, but I'm a little confused about how to go about it. When I'd get the data for blocks I'd use get_param, but I want to get the parameters of the model. Would I go about it the same way? Thanks.
0 comentarios
Respuesta aceptada
Kaustubha Govind
el 6 de Jun. de 2012
You can set_param for the model also:
set_param('modelname', 'StopTime', '3000')
3 comentarios
Ben MacCallum
el 26 de Mzo. de 2021
If you are using the sim function to run your model, you can set the stop time as follows,
sim('model_name', 'StopTime', '40');
Athira Km
el 12 de Ag. de 2021
Thank you but how to set this dynamically from a parameter instead of a constant value?
Más respuestas (1)
Bill Tubbs
el 25 de Nov. de 2021
You can also do it by passing it as an argument when you run the simulation from the m file:
sim_out = sim(sim_model, t_stop)
3 comentarios
Bill Tubbs
el 15 de Nov. de 2022
Editada: Bill Tubbs
el 15 de Nov. de 2022
Hmm. Not sure. Are you converting t_stop to a string? This is the exact statement I am using right now with MATLAB v2021b. Maybe you need to include the option char array like this:
sim_out = sim(sim_model, 'StartTime', '0', 'StopTime', string(t(end)));
Bill Tubbs
el 15 de Nov. de 2022
Actually, the original code I posted above where t_stop is a number does also work in 2021b. Maybe this behaviour has been removed in recent versions. Nevertheless, maybe it's best to always include 'StopTime' and use string(t_stop).
Ver también
Categorías
Más información sobre Programmatic Model Editing 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!