Set Simulink model simulation stop time from m file
显示 更早的评论
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.
采纳的回答
更多回答(1 个)
Bill Tubbs
2021-11-25
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 个评论
Paul
2022-11-15
This doesn't work anymore. Has the syntax changed recently?
I get the following error:
Expected a string scalar or character vector for the parameter name.
Bill Tubbs
2022-11-15
编辑:Bill Tubbs
2022-11-15
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
2022-11-15
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).
类别
在 帮助中心 和 File Exchange 中查找有关 Programmatic Model Editing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!