Simulink: How do I change the value of a gain block with code?
Ältere Kommentare anzeigen
I would like to change the value of a gain block with Matlab code. I tried using the ModelWorkspace along with assignin, but the problem with this method is that I cannot generate C code from it.
What is the best way to modify a variable gain block and still be able to generate C code from the Simulink block diagram?
Thank you.
5 Kommentare
Robert
am 8 Aug. 2016
Your intent is not clear. What do you mean you cannot generate code using a variable in the model workspace?
J H
am 9 Aug. 2016
Robert
am 9 Aug. 2016
Thanks for clarifying.
When you say "iteration" are you referring to each time step in the simulation or each run of the model from start to stop?
If you want to change the gain before each time you call the model, you could use a script that sets your variable then runs the model in a loop over each value of your gain. In normal and accelerator modes this is pretty straightforward. In rapid accelerator it is a little more tricky but still manageable.
If you are trying to modify the gain while the model is running, perhaps a multiplication operator would be more suitable.
J H
am 9 Aug. 2016
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Programmatic Model Editing finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!