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...

 Accepted Answer

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 Comments

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...
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....

Sign in to comment.

More Answers (2)

1 Comment

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...

Sign in to comment.

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 Comments

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?
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).

Sign in to comment.

Products

Community Treasure Hunt

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

Start Hunting!