Deviltrigger
Deviltrigger

Reputation: 63

How to change the value of simulink block during the simulation?

i have a constant block in a simulink model; i would like to change its value during the simulation when a particular event occurred in a stateflow chart. how can i do it?

enter image description here

Upvotes: 0

Views: 8690

Answers (2)

am304
am304

Reputation: 13886

You can also add a Slider Gain block between your constant block and the Stateflow block. This would allow you to change the value of the slider gain block during simulation, without the need to change the value of the constant block.

Upvotes: 0

Praetorian
Praetorian

Reputation: 109259

If the Stateflow chart output indicates when this event has occurred, or if you can add an additional output that toggles when the event occurs, loop this indicator back (possibly through a Unit Delay block) to the control input of Switch block. The two inputs to the Switch would be two Constant blocks containing the two different values.

If you must do this programmatically without modifying the model, take a look at the reference for the sim command. I should warn you that this may not be trivial to accomplish.

Also, if want to be able to modify the contents of a Constant block mid-simulation (i.e. make it tunable), you may have to turn off Simulink's optimization settings that inline invariant parameters.

Upvotes: 1

Related Questions