Main Content

get_param

Get parameter names and values

Description

value = get_param(object,parameter) returns the value value of the specified parameter parameter for the target object specified by object. The target object can be a model, subsystem, library, block, line, port, or bus element port element specified as a path or a handle.

Open or load the related Simulink® model, subsystem, or library before calling this function.

example

Examples

collapse all

You can get the value of a block parameter using the get_param function with these input arguments:

  • Block handle or full block path including block name, for example, 'myModel/mySubsystem/myblock'

  • Parameter name

For more information about block handles and paths, see Get Handles and Paths.

In this example, you get the coefficients of the transfer function specified by a Transfer Function block named Alpha-sensor Low-pass Filter.

  • The block is located in the Controller subsystem of the slexAircraftExample model.

  • The coefficients of the transfer function numerator are stored in the Numerator parameter. The coefficients of the transfer function denominator are stored in the Denominator parameter.

Open the example. Then, load the slexAircraftExample model.

mdl = 'slexAircraftExample';
load_system(mdl)

Get the transfer function coefficients.

path = [mdl,'/Controller/Alpha-sensor Low-pass Filter'];
num = get_param(path,'Numerator')
num = 
'[1]'
denom = get_param(path,'Denominator')
denom = 
'[Tal,1]'

When the block path is long and you want to get multiple parameters, consider using block handles.

You can get the value of a block parameter using the get_param function with these input arguments:

  • Block handle or full block path including block name, for example, 'myModel/mySubsystem/myblock'

  • Parameter name

In this example, you get the coefficients of the transfer function specified by a Transfer Function block named Alpha-sensor Low-pass Filter.

  • The block is located in the Controller subsystem of the slexAircraftExample model.

  • The coefficients of the transfer function numerator are stored in the Numerator parameter. The coefficients of the transfer function denominator are stored in the Denominator parameter.

Open the example. Then, get the block handle using the getSimulinkBlockHandle function. To simultaneously get the block handle and load the model, specify the second argument for the getSimulinkBlockHandle function as true.

path = 'slexAircraftExample/Controller/Alpha-sensor Low-pass Filter';
h = getSimulinkBlockHandle(path,true)
h = 
490.0016

To get the parameter values, specify the block using the handle. Do not manually enter the value of the handle. The value output by the getSimulinkBlockHandle function in the MATLAB® Command Window may not match the handle value due to rounding. Instead, assign the handle to a variable, then use the variable name to specify the block. In this example, the value is assigned to the variable named h.

num = get_param(h,'Numerator')
num = 
'[1]'
denom = get_param(h,'Denominator')
denom = 
'[Tal,1]'

You can get the value of a block parameter using the get_param function with these input arguments:

  • Block handle or full block path including block name, for example, 'myModel/mySubsystem/myblock'

  • Parameter name

This example shows how to get the parameter name.

Suppose you want to get the transfer function coefficients of the Transfer Function block named Alpha-sensor Low-pass Filter in the slexAircraftExample model. To do so, you must get the names of the parameters that store the transfer function coefficients.

Open the example.

Get the handle of the Transfer Function block named Alpha-sensor Low-pass Filter. To simultaneously get the block handle and load the model, specify the second argument for the getSimulinkBlockHandle function as true.

path = 'slexAircraftExample/Controller/Alpha-sensor Low-pass Filter';
h = getSimulinkBlockHandle(path,true);

Get the names of all the block parameters of the Transfer Function block named Alpha-sensor Low-pass Filter using the get_param function.

get_param(h,'DialogParameters')
ans = struct with fields:
                    Numerator: [1×1 struct]
                  Denominator: [1×1 struct]
          ParameterTunability: [1×1 struct]
            AbsoluteTolerance: [1×1 struct]
    ContinuousStateAttributes: [1×1 struct]

The output shows that the transfer function coefficients are specified using a Numerator parameter and a Denominator parameter. Use these parameter names to get the coefficients in the numerator and denominator of the transfer function.

num = get_param(h,'Numerator');
denom = get_param(h,'Denominator')
denom = 
'[Tal,1]'

You can get the value of a block parameter using the get_param function with these input arguments:

  • Block handle or full block path including block name, for example, 'myModel/mySubsystem/myblock'

  • Parameter name

This example shows how to get the full block path of all blocks in a model with a certain keyword in their name. For more information about how to get block paths, see Get Handles and Paths.

Suppose you want to get the transfer function coefficients of all Transfer Function blocks that act as filters in the slexAircraftExample model.

Open the example. Then, load the slexAircraftExample model.

mdl = 'slexAircraftExample';
load_system(mdl)

Get the paths of all blocks in the slexAircraftExample model whose name contains the word filter using the find_system function. Use regular expressions, make the search case insensitive, and limit the search to blocks. To use regular expressions, set the value of the Regexp parameter to 'on'. To make the search case insensitive, set the value of the CaseSensitive parameter to 'off'. To limit the search to blocks, set the value of the Type parameter to 'Block'.

paths = find_system(mdl,Regexp='on',CaseSensitive='off',Type='Block',Name='.*filter.*')
paths = 3×1 cell
    {'slexAircraftExample/Controller/Alpha-sensor↵Low-pass Filter'}
    {'slexAircraftExample/Controller/Pitch Rate↵Lead Filter'      }
    {'slexAircraftExample/Controller/Stick↵Prefilter'             }

When you do not specify a search depth, the find_system function finds all blocks in the specified level of the model hierarchy and in all lower levels the specified level contains. Since slexAircraftExample is the top level of the model hierarchy, the command returns all blocks from every level of the model hierarchy.

Use the block paths to get the transfer function coefficients. For example, use these commands to get the transfer function coefficients for the Alpha-sensor Low-Pass filter.

num = get_param(paths{1},'Numerator')
num = 
'[1]'
denom = get_param(paths{1},'Denominator')
denom = 
'[Tal,1]'

Get a list of the types of blocks in the vdp model.

Open the example. Then, load the vdp model.

load_system('vdp')

Get a list of block paths and names for the vdp model.

blockpaths = find_system('vdp','Type','Block');

For each block in the vdp model, get the value of the BlockType parameter.

blocktypes = get_param(blockpaths,'BlockType')
blocktypes = 12×1 cell
    {'CustomCallbackButton'}
    {'Constant'            }
    {'SubSystem'           }
    {'Product'             }
    {'Scope'               }
    {'Math'                }
    {'Sum'                 }
    {'Sum'                 }
    {'Integrator'          }
    {'Integrator'          }
    {'Outport'             }
    {'Outport'             }

You can get the value of a model parameter using the get_param function with these input arguments:

  • Model name

  • Model parameter name

The value of the IntegerOverflowMsg parameter indicates how a model handles integer overflow. The model can output no message, a warning message, or an error message.

Suppose you want to compare the value of the IntegerOverflowMsg parameter of two models.

Open the example. Then, load the vdp and f14 models.

load_system({'vdp','f14'})

Get the value of the IntegerOverflowMsg parameter for the vdp and f14 models.

vdpval = get_param('vdp','IntegerOverflowMsg');
f14val = get_param('f14','IntegerOverflowMsg');

When integer overflow occurs, the vdp model outputs a warning, while the f14 model does not output any message.

Compare the two parameter values using the strcmp function.

strcmp(vdpval,f14val)
ans = logical
   0

The strcmp function outputs 0, which indicates that the two models have different values for the IntegerOverflowMsg parameter.

You can get the value of a model parameter using the get_param function with these input arguments:

  • Model name

  • Model parameter name

Suppose you want to compare the message parameter values of two models to ensure consistency in terms of which situations are handled with no message versus a warning message versus an error message. However, you do not know the names of all the message parameters.

Open the example. Then, load the vdp and f14 models.

load_system({'vdp','f14'})

Get a list of all model parameters.

params = get_param('vdp','ObjectParameters');

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

names = fieldnames(params);

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

msgnames = names(contains(names,'Msg'));

Compare the message parameter values of the vdp and f14 models. Output the names of the parameters that have different values.

vdpval = cell(1,length(msgnames));
f14val = vdpval;

for i=1:length(msgnames)
    vdpVal{i} = get_param('vdp',msgnames{i});
    f14Val{i} = get_param('f14',msgnames{i});
    if(strcmp(vdpVal{i},f14Val{i})<1)
        disp(msgnames{i})
    end
end
IntegerOverflowMsg
IntegerSaturationMsg

Two message parameters have different values.

To get a list of options for any of these, use the get_param function with the keyword options:

  • A block parameter

  • A model parameter

  • Object properties, for example, the horizontal alignment options for an annotation

This example shows how to get a list of options for a block parameter, a masked parameter, and a model parameter.

Get List of Options for Block Parameter

Open the example. Then, load the vdp model.

load_system('vdp')

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

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

Get List of Options for Masked Subsystem Parameter

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

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

Get List of Options for Model Parameter

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

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

Get List of Options for Annotation

Find the annotations in the vdp model.

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

Output the annotation text corresponding to the handles in the matrix h.

get_param(h,'PlainText')
ans = 3×1 cell
    {'Copyright 2004-2024 The MathWorks, Inc.'}
    {'Van der Pol Equation'                   }
    {'x_1' =x_2↵↵x_2' =µ(1-x_1^2) x_2 - x_1'  }

Get a list of options for the horizontal alignment of the title annotation, 'Van der Pol Equation'.

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

You can access the value of a masked block parameter using the get_param function with the keyword value.

Open the example. Then, open the vdp model.

open_system('vdp')

Get the value of the gain parameter of the masked Subsystem block named Mu.

get_param('vdp/Mu','value@gain')
ans = 
2

In the model, double-click the block.

On the mask, move the slider that changes the gain parameter.

Get the value of the gain parameter again.

get_param('vdp/Mu','value@gain')
ans = 
2

Get the name and value of a global parameter.

Get List of Global Parameter Names

You can get a list of global parameter names by finding the difference between the Simulink® root parameter and the model parameter names.

Open the example. Then, load the vdp model.

load_system('vdp')

Get the names of all model parameters.

modelparamnames = fieldnames(get_param('vdp','ObjectParameters'));

Get a list of Simulink root parameter names.

rootparamnames = fieldnames(get_param(0,'ObjectParameters'));

Get the names of global parameters by finding the difference between the lists of root and model parameter names.

globalparamnames = setdiff(rootparamnames,modelparamnames);

Get Global Parameter Value

Get the value of a global parameter.

globalparamval = get_param(0,'CurrentSystem')
globalparamval = 
'vdp'

Input Arguments

collapse all

Name, path, or handle of object or root, specified as a character vector, cell array of character vectors, string array, numeric scalar, or 0.

How you specify the target object depends on its type.

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

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: 'vdp/Mu'

Example: 'mymodel/Subsystem1/Out1.nonsinusoidal.saw'

Tips

  • If you make multiple calls to get_param for the same block, specify the block with a numeric handle. This method is more efficient than using the full block path with get_param. Use getSimulinkBlockHandle to get a block handle.

  • Do not try to manually specify the number of a handle, for example, 5.007, because you usually need to specify more digits than MATLAB® displays. Assign the handle to a variable and use that variable name.

Data Types: char | string | double

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

This table shows special cases.

Specified ParameterResult
'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.

'ParameterStruct'

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 reference pages. For example:

Example: 'ObjectParameters'

Example: 'Solver'

Example: 'SimulationCommand'

Example: 'Position'

Example: 'NameLocation'

Data Types: char | string

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.

Specified ParameterResult
'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