Main Content

get_param

R2026b

Get parameter names and values

Description

value = get_param(Object,Parameter) returns the value of the specified parameter for the target object. For example, you can use this syntax to get the amplitude value of a Sine Wave block. The target object can be a model, subsystem, library, block, line, port, or bus element port element specified as a handle or path. For information on how to get handles and paths, see Get Handles and Paths.

To query a Simulink® model, subsystem, or library or its content, the model, subsystem, or library must be loaded or open.

example

Examples

collapse all

Suppose you have a loaded model named myModel that contains a Subsystem block named mySubsystem. The subsystem contains a Gain block named myBlock. Get the gain value.

To get the value, you need two inputs:

In this example, you have enough information to get the block path. The block path is the path through the model hierarchy from the root of the model to the block, with each step through the hierarchy separated by a forward slash. Store the block path in a variable.

blockPath = "myModel/mySubsystem/myBlock";

Get the programmatic name of the parameter you want to query. One way to do so is to check the documentation for the block. On the documentation page for the block, in the Parameters section, find the parameter. Then, check the Programmatic Use section for the programmatic name.

For this example, check this page for the parameter name: Gain. The programmatic name of the parameter storing the gain value is Gain.

Get the parameter value.

gainValue = get_param(blockPath,"Gain");

If you want to run more operations on the block, consider using its handle instead of the block path. To get the handle from the block path, use the getSimulinkBlockHandle function.

h = getSimulinkBlockHandle(blockPath);

Get the parameter value using the handle.

gainValue = get_param(h,"Gain");

Suppose you have a loaded model with a complex hierarchy containing hundreds of blocks. The handle of the model is stored in the variable h. Get the transfer function coefficients of all Transfer Fcn blocks whose name contains the key phrase Low-Pass Filter.

To get the values of the coefficients, you need two inputs:

Get the handles of the Transfer Fcn blocks whose name contains the key phrase Low-Pass Filter. Use the find_system function.

hBlocks = find_system(h,Regexp="on",CaseSensitive="on",Type="Block",BlockType="TransferFcn",Name=".*Low-Pass Filter.*")

Get the programmatic names of the parameters that store the transfer function coefficients. Open the documentation page for the Transfer Fcn block: Transfer Fcn. In the Parameters section, find the parameter you want to query. Then, check the Programmatic Use section for the programmatic name. The numerator coefficients are stored in the parameter with the programmatic name Numerator, and the denominator coefficients are stored in the parameter with the programmatic name Denominator.

Get the coefficient values.

numeratorCoeffs = get_param(hBlocks,"Numerator");
denominatorCoeffs = get_param(hBlocks,"Denominator");

Suppose you have two loaded models, myModel1 and myModel2. Check that both models have the same message parameter values.

Get a list of the model parameters.

params = get_param("myModel1","ObjectParameters");

The function returns a structure. Create a cell array that contains the model parameter names.

paramNames = fieldnames(params);

Message parameters end in the abbreviation Msg. Get the all model parameter names that contain the abbreviation Msg.

msgNames = paramNames(contains(paramNames,'Msg'));

Compare the message parameter values of the two models. Display the names of the parameters that have different values.

mdl = ["myModel1";"myModel2"];

for i=1:length(msgNames)
    val = get_param(mdl,msgNames{i});
    if(length(unique(val))~=1)
        disp(msgNames{i})
    end
end

Some of the parameters that you can query using the get_param function have a finite number of permissible values. For example, the icon shape parameter of a Sum block can only have one of two values: rectangular or round. To get a list of the available value options for a parameter, use the get_param function as you would if you wanted to get the parameter value, but add the prefix options@ to the parameter name you specify in the function inputs.

Suppose you have a loaded model named myModel. The model contains a Square block named mySquareBlock, a masked Subsystem block named mySubsystemBlock, and an annotation.

Get a list of options for the Output signal type parameter of the Square block.

funcoptions = get_param("myModel/mySquareBlock","options@OutputSignalType")
funcoptions = 1×3 cell
    {'auto'}    {'real'}    {'complex'}

Get a list of options for the masked subsystem parameter Read/Write permissions of the Subsystem block.

get_param("myModel/mySubsystemBlock","options@Permissions")
ans = 1×3 cell
    {'ReadWrite'}    {'ReadOnly'}    {'NoReadOrWrite'}

Get a list of options for the model parameter named AlgebraicLoopMsg.

get_param("myModel","options@AlgebraicLoopMsg")
ans = 1×3 cell
    {'none'}    {'warning'}    {'error'}

Get a list of options for the horizontal alignment of the annotation. To do so, get the handle of the annotation.

h = find_system(gcs,FindAll="on",Type="annotation");

Then, get the list of options.

get_param(h,"options@HorizontalAlignment")
ans = 1×3 cell
    {'left'}    {'center'}    {'right'}

To get the value of a mask parameter that is set to a variable, use the get_param function. Add the prefix value@ to the parameter name you specify in the function inputs.

Note

For Popup and Radio button mask parameters that use string as type options without values, the evaluated value is the index of the selected option.

Suppose you have a model named myModel that contains a masked Subsystem block named myBlock. The mask has a slider with the parameter name magnitude. The value of the parameter is set to a base variable. Get the name and value of the variable.

Start by getting the name. To do so, get the value of the magnitude parameter using the get_param function. The parameter is set to the variable, so querying the parameter value will return the variable name.

blockPath = "myModel/myBlock";
varName = get_param(blockPath,"magnitude");

Then, get the variable value. Use the same command as before, but add the prefix value@ before the parameter name.

varValue = get_param(blockPath,"value@magnitude");

Suppose you have a loaded model named myModel. Get a list of global parameter names. Then, get the value of the global parameter named CurrentSystem.

To get a list of global parameter names, find the difference between the Simulink root parameter names and the model parameter names.

Get the names of the model parameters.

modelParamNames = fieldnames(get_param("myModel","ObjectParameters"));

Get the names of the Simulink root parameter names.

rootParamNames = fieldnames(get_param(0,"ObjectParameters"));

Get the names of the global parameters.

globalParamNames = setdiff(rootParamNames,modelParamNames);

Get the value of the global parameter named CurrentSystem.

globalparamval = get_param(0,"CurrentSystem")
globalparamval = 
'myModel'

Input Arguments

collapse all

Handle, name, or path of target object, or root, to query. How you can specify the target object depends on the type of target object.

  • Model — Model name or handle.

  • Subsystem — Subsystem name or handle.

  • Library — Library name or handle.

  • Block — Block path or handle.

  • Line — Line handle.

  • Port — Port handle.

  • Port element — Path composed of the model name or subsystem block path, a forward slash, and the port name or bus element path. For a bus element port, the bus element path provides the hierarchy from the top-level bus to the target element, separating each name in the hierarchy with a dot.

For information about how to get handles and paths, see Get Handles and Paths. Format handles as numeric scalars or numeric vectors. Format names and paths as strings, string arrays, character vectors, or cell arrays of character vectors.

Specify 0 to get root parameter names, including global parameters and model parameters for the current Simulink session.

  • Global parameters include Editor preferences and Simulink Coder™ parameters.

  • Model parameters include configuration parameters, Simulink Coder parameters, and Simulink Code Inspector™ parameters.

Example: "myModel/mySubsystem/myBlock"

Data Types: double | array of doubles | string | string array | character vector | cell array of character vectors

Parameter, property, or attribute name, specified as a string or character vector. Some names are case sensitive.

This table shows special cases.

ParameterValue
ObjectParameters

Parameter names of the specified object as separate fields in a structure array.

DialogParameters

Block dialog box parameter names as separate fields in a structure array. If the block has a mask, the function instead returns the mask parameters.

ParameterValuesStruct

Structure containing parameter names and their current values for any masked block.

For information about parameters, properties, or attributes, see the Programmatic Use information on the corresponding documentation pages. For example:

Example: "ObjectParameters"

Example: "Solver"

Example: "SimulationCommand"

Data Types: string | character vector

Output Arguments

collapse all

Parameter value, returned in the format determined by the parameter type. If you specify multiple objects, the output is a cell array.

This table shows special cases.

ParameterValue
ObjectParameters

Parameter names of the specified object as separate fields in a structure array.

DialogParameters

Block dialog box parameter names as separate fields in a structure array. If the block has a mask, the function instead returns the mask parameters.

If you get the root parameters by specifying get_param(0,"ObjectParameters"), then the output value is a structure array with the root parameter names as separate fields in the structure. Each parameter field is a structure containing these fields:

  • Type — Parameter type values are 'boolean', 'string', 'int', 'real', 'point', 'rectangle', 'matrix', 'enum', 'ports', or 'list'.

  • Enum — Cell array of enumeration character vector values that applies only to 'enum' parameter types.

  • Attributes — Cell array of character vectors defining the attributes of the parameter. Values are 'read-write', 'read-only', 'read-only-if-compiled', 'write-only', 'dont-eval', 'always-save', 'never-save', 'nondirty', or 'simulation'.

Version History

Introduced before R2006a