How to change the parameter value at run time in Matlab Simulink

31 views (last 30 days)
I want to change the input of model at run time.
Model and .m file is attached.
Input is coming from Switch block and Current (10) matlab parameter is connect to switch block defined in base workspace. Canc check in .m file.
The output of switch block goes to stateflow. In stateflow transition is[duration(Current>Current_TH)>0.2) than fault will set and if Current is less than Current_TH fault will clear.
Here Current value is 10 and Current_TH is 20.
Current_TH aslo i created as matlab parameter in base workspace.
How can change the current value at run time menas to set fault need to set current value greater than 21 and to clear fault current value less than 20 while running the model. How to make it happen at run time.
Please suggest any solution.
Thank you!!

Answers (2)

Fangjun Jiang
Fangjun Jiang on 8 Apr 2024 at 12:31
This is not "change the parameter value at run time". Rather, it is to mimic a dynamic signal. You can use many of the blocks in the Simulink -> Sources library, for example, Step, Sine Wave, Signal Generator, etc.
The Step block changes the value once at a particular time. This could fit your need immediately.

Aquatris
Aquatris on 8 Apr 2024 at 12:52
I think what you are looking for is the dashboard, link here. It provides an interactive interface with a running model.
  3 Comments
Aquatris
Aquatris on 9 Apr 2024 at 7:44
Then maybe this example is what you are looking for. It changes the value of a parameter in the simulink model on run time via matlab script.
Fangjun Jiang
Fangjun Jiang on 9 Apr 2024 at 11:42
Don't remember if the following feature is available in R2017a but you could try. It is available in recent versions.
Set the model to run simulation for a very long time or "inf", while the simulation is running, double click the Constant block with "Current" as the value, simply change the value to be 20 or 0.2 or whatever. Hit return and the new value will be used. This will help you debug the Stateflow chart.
If the need is to vary the value of "Current" to observe or debug the Stateflow, then replace the "Current" Constant block with a Step block or a Signal Generator block would be the solution. Setting the parameter to be tunable or settign the storage class is a completely wrong direction.

Sign in to comment.

Categories

Find more on Simulink Functions in Help Center and File Exchange

Products


Release

R2017a

Community Treasure Hunt

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

Start Hunting!