changing a parameter inside a continuous transfer function during simulation

5 vues (au cours des 30 derniers jours)
Danilo NASCIMENTO
Danilo NASCIMENTO le 16 Août 2015
Commenté : Sebastian Castro le 17 Août 2015
Hey guys, I want to change a parameter of a continuous transfer function during a simulation. Is that possible?

Réponses (1)

Sebastian Castro
Sebastian Castro le 17 Août 2015
Yes, it is possible.
You can go right into the block and change the parameters mid-simulation. When you hit "OK" in the block, the parameters update.
If you want to do this programmatically, you can do the following -- suppose you are changing a parameter K in a model called myModel:
>> K = 0.2;
>> set_param('myModel','SimulationCommand','update');
- Sebastian
  2 commentaires
Danilo NASCIMENTO
Danilo NASCIMENTO le 17 Août 2015
Well, it can be useful. But this is not what I mean. I don't want to change it manually. For instance, let's suppose I have a continuous transfer function called G(s)=1/(s^2+w0^2), I want to change the parameter w0 at time 0.4 s with a command. This is all in simulink.
Sebastian Castro
Sebastian Castro le 17 Août 2015
I just tried this out by putting the above MATLAB commands inside a MATLAB Function block. Notice a few subtle changes like declaring some functions extrinsic (due to code generation), and also assigning values in the MATLAB base workspace with assignin (a necessary "evil" in this case).
coder.extrinsic('assignin');
coder.extrinsic('set_param');
assignin('base','w0',5);
set_param('untitled','SimulationCommand','update');
This is then placed inside a Triggered Subsystem that triggers when the simulation time exceeds a certain value. For example:
Notice that I am changing the frequency w0 from 1 to 5 at a time of 4 seconds. My results change as follows:
- Sebastian

Connectez-vous pour commenter.

Catégories

En savoir plus sur Schedule Model Components dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by