This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Parameterize a Referenced Model Programmatically

This example shows how to programmatically configure multiple instances of a referenced model to use different values for the same block parameter.

Configure Referenced Model to Use Model Arguments

When you simulate a model, the parameter objects in the model workspace use the values that you specify for the Simulink.Parameter objects, Simulink.LookupTable objects, or MATLAB® variables. The block parameters also use these values.

To configure the Gain parameter of a Gain block and the Numerator parameter of a Discrete Filter block as model arguments, follow these steps.

Open model ex_model_arg_ref. This model represents a reusable algorithm.


For the Gain block, set the value of the Gain parameter to a Simulink.Parameter object in the model workspace with a numeric value. For this example, name the Simulink.Parameter object gainArg and assign a value of 3.17.

modelWorkspace = get_param('ex_model_arg_ref','ModelWorkspace');

For the Discrete Filter block, set the value of the Numerator parameter to a Simulink.Parameter object in the model workspace with a numeric value. For this example, name the Simulink.Parameter object coeffArg and assign a value of 1.05.

set_param('ex_model_arg_ref/Discrete Filter','Numerator','coeffArg')

Specify gainArg and coeffArg as model arguments.


Set Model Argument Values in Parent Model

When you simulate a parent model, each instance of a reusable referenced model uses the argument values that you specify in the parent model. In this example, in the upper instance of ex_model_arg_ref, the parameter object gainArg uses the value 2.98.

Model ex_model_arg contains two Model blocks that reference ex_model_arg_ref. To set different parameter values for the two instances of the model, follow these steps.

Open model ex_model_arg. This model represents a system model that uses multiple instances of the reusable algorithm.


For both instances of model ex_model_arg, set values for the model arguments. If you decide to re-promote these arguments, set the Argument field to true. By default, the Argument field is false.

instSpecParams = get_param('ex_model_arg/Model','InstanceParameters');
instSpecParams1 = get_param('ex_model_arg/Model1','InstanceParameters');

instSpecParams(1).Value = '.98';
instSpecParams(2).Value = '2.98';
instSpecParams1(1).Value = '1.11';
instSpecParams1(2).Value = '3.34';
instSpecParams(1).Argument = true;
instSpecParams(2).Argument = true;
instSpecParams1(1).Argument = true;
instSpecParams1(2).Argument = true;


Related Topics