MATLAB Answers


assign parameter values with sim command

Asked by Ben
on 19 Jul 2013

Suppose I have a Simulink model called myModel.mdl. One of the blocks has a parameter, and I have assigned to it the variable:


If I want to set this variable to 0.5 and run the model, then the following code suffices:


However for reasons too complicated to explain here, I would like to make the first command part of the second. If sfreq were a MODEL parameter then I would simply do the following:


Unfortunately sfreq is a block parameter, and so I get back the following error:

block_diagram does not have a parameter named 'sfreq'

Any ideas for avoiding this error?





No products are associated with this question.

1 Answer

Answer by Azzi Abdelmalek
on 19 Jul 2013
Edited by Azzi Abdelmalek
on 19 Jul 2013
 Accepted answer

Use set_param function



on 19 Jul 2013


Thank you for the suggestion. That command is exactly what I tried first. Unfortunately I won't always have access to the parameter name, which is apparently required for set_param. I can automatically find the BLOCKS in which the parameter appears by using the following command:


But I cannot actually find the NAMES of the parameters in the blocks which are set to the variable sfreq.

Azzi Abdelmalek
on 19 Jul 2013

You can get the name of your parameter by

get_param('yourmodel/yourblockName', 'Dialogparameters')

Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi test

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!