Set Simulink model simulation stop time from m file

조회 수: 182 (최근 30일)
Lucas
Lucas 2012년 6월 6일
댓글: Bill Tubbs 2022년 11월 15일
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.

채택된 답변

Kaustubha Govind
Kaustubha Govind 2012년 6월 6일
You can set_param for the model also:
set_param('modelname', 'StopTime', '3000')
  댓글 수: 3
Ben MacCallum
Ben MacCallum 2021년 3월 26일
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
Athira Km 2021년 8월 12일
Thank you but how to set this dynamically from a parameter instead of a constant value?

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Bill Tubbs
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
Bill Tubbs
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
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).

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Programmatic Model Editing에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by