Varying parameters During a simulation

8 次查看(过去 30 天)
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
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 个评论
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.

请先登录,再进行评论。

更多回答(2 个)

Walter Roberson
Walter Roberson 2011-7-19
  1 个评论
Vinol Joy D'souza
Vinol Joy D'souza 2011-7-19
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
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).

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Programmatic Model Editing 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by