How do I change an instance parameter in the model reference's model workspace in between simulations when the using Fast Restart mode?

I am attempting to change an instance parameter in between simulations. I have a reference model which multiplies a sinusoid by a scalar. This scalar value is dictated by a model workspace variable named "Param". When I do not have Fast Restart mode on, I am able to change the variable value by using "setVariable" and a Simulation Input object. However, these changes do not persist when Fast Restart mode is turned on. 
How can I accomplish this workflow when using Fast Restart mode?

 采纳的回答

Changing the model workspace between simulations when using Fast Restart is not supported. However, you can use the base workspace to change the instance parameter value being used by the reference model. To do this, follow the steps below:
1. Open your top-level model, right-click on your reference model, and select "Block Parameters"
2. Click on the "Instance Parameters" tab, set the value of your parameter as a new variable (e.g. "p"), and save the model.
3. Define the variable in your base workspace as any initial value
4. Change your base workspace variable to anything you like between simulations by using the code below:
simIn=simIn.setVariable('p',n);
This code will set the instance parameter of the reference model to be different for each "SimulationInput" object.

更多回答(0 个)

类别

在 帮助中心 和 File Exchange 中查找有关 Model, Block, and Port Callbacks 的更多信息

产品

版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by