Varying parameters During a simulation

Hi,
I want to change the parameters of a block when the model is running and simultaneously see the changes in the output.
For eg.I have a sine block connected to a Scope.and when i start the simulation.I want to change the frequency of the sine wave and see the corresponding frequency changed wave on the scope output.I want to do this as i want to see how my model behaves for different frequencies.
Somebody please help me in this regard....Please comment and let me know..I will be grateful to who answer my question...

 채택된 답변

Arnaud Miege
Arnaud Miege 2011년 7월 19일

1 개 추천

Also have a look at this example on the File Exchange. You can use a similar technique to change the frequency of your sine wave from the GUI while the model is running.
HTH,
Arnaud

댓글 수: 5

thank you...that was pretty much what i was looking for...
But the matlab script for the GUI is pretty lengthy though..
thank you very much for your timely help...
Can you pour some light on the differences between GRT and Simulation....and also the Build and Start button
You have changed the gain of the sine wave in this program...If i want to change the frequency on the GUI..What changes should i do???..
I would be grateful if you guide me through this...
Arnaud Miege
Arnaud Miege 2011년 7월 20일
You'd be better contacting the author of the file (that's not me). I provided this as an example, it's up to you to adapt it for your particular needs. Simulation is standard simulation in Simulink, GRT uses Simulink Coder to generate C code and compile it into an executable that is then run (outside of MATLAB and Simulink). Build is the process of generating that C code and compiling it into an executable.
Thank you very much....

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Walter Roberson
Walter Roberson 2011년 7월 19일

0 개 추천

댓글 수: 1

I want to have a gui kind of thing in the model like a frequency knob and when i vary it i should see the frequency change on the scope...

댓글을 달려면 로그인하십시오.

Fangjun Jiang
Fangjun Jiang 2011년 7월 19일

0 개 추천

If you only want to do this with sine wave frequency, you can use a slider gain block and then use a Fcn block, y=sin(2*pi*f*t).
If you want to do this in general, follow the link that Walter provided. Do the following in your GUI callback function.
set_param(YourModel, 'SimulationCommand', 'pause');
set_param(YourBlock, parameter, value);
set_param(YourModel, 'SimulationCommand', 'continue');

댓글 수: 2

Walter Roberson
Walter Roberson 2011년 7월 19일
Under what circumstances would one need to command an 'update' after set_param() ? Are there circumstances under which doing so would mess up what one is already doing?
Fangjun Jiang
Fangjun Jiang 2011년 7월 19일
Here is a link http://www.mathworks.com/help/toolbox/simulink/ug/brbj30f.html. The most relevant info is in the paragraph started with "A tunable parameter" and the one after. In 2010b, it is much easier to find the related information.
Basically, if a block parameter can be changed through parameter dialog while the simulation is running, You don't need to update the model. The simulation will simply resume. For others, you'll need to update the model which means re-start the simulation. I tried. I can pause the simulation of a model. Then I can change the gain value of a Gain block but I can't change the sample time of the Gain block. In parameter dialog, those parameters are disabled (grayed out).

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Model, Block, and Port Callbacks에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by