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

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)

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.
I think what you are looking for is the dashboard, link here. It provides an interactive interface with a running model.

3 Comments

@Aquatris Thank you for answer, but i am not looking any dashboard. I want to tune the parameter from .m file or .mat file within the simulimk model. I have a differnet logic in that there no use of knob, gauage etc..
I want add one more information
Configuration setting>Optimization>Signal and Parameter, selected the Inline behaviour and click on configure and selected the MATLAB workspace variable to tune parameter.
Matlab version - 2017a
Please let me know your respone.
Thank you once again!!
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.
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

Products

Release

R2017a

Asked:

on 8 Apr 2024

Commented:

on 9 Apr 2024

Community Treasure Hunt

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

Start Hunting!