Documentation

get_param

Get parameter names and values

Syntax

  • ParamValue = get_param(Object,Parameter) example

Description

example

ParamValue = get_param(Object,Parameter) returns the name or value of the specified parameter for the specified model or block object. Open or load the Simulink® model first.

    Tip   If you make multiple calls to get_param for the same block, then specifying the block using a numeric handle is more efficient than using the full block path. Use getSimulinkBlockHandle to get a block handle.

For parameter names, see:

Examples

collapse all

Get a Block Parameter Value and a Model Parameter Value

Load the vdp model.

load_system('vdp');

Get the value for the Expression block parameter.

BlockParameterValue = get_param('vdp/Fcn','Expression')
BlockParameterValue =
    1 - u*u

Get the value for the SolverType model parameter.

SolverType = get_param('vdp','SolverType')
SolverType =
   Variable-step

Get Root Parameter Names and Values

Get a list of global parameter names by finding the difference between the Simulink root parameter names and the model parameter names.

RootParameterNames = fieldnames(get_param(0,'ObjectParameters'));
load_system('vdp')
ModelParameterNames = fieldnames(get_param('vdp','ObjectParameters'));
GlobalParameterNames = setdiff(RootParameterNames,ModelParameterNames)
GlobalParameterNames =
          'AutoSaveOptions'
          'CacheFolder'
          'CallbackTracing'
          'CharacterEncoding'
                 . . .
          'CurrentSystem'

Get the value of a global parameter.

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

Get Model Parameter Names and Values

Get a list of model parameters for the vdp model .

load_system('vdp')
ModelParameterNames = get_param('vdp','ObjectParameters')
ModelParameterNames =
              Name: [1x1 struct]
               Tag: [1x1 struct]
       Description: [1x1 struct]
              Type: [1x1 struct]
            Parent: [1x1 struct]
            Handle: [1x1 struct]
                       . . .
           Version: [1x1 struct]

Get the current value of the ModelVersion model parameter for the vdp model.

ModelParameterValue = get_param('vdp','ModelVersion')
ModelParameterValue =
          1.6

Get All Block Parameter Names and Values

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

load_system('vdp')
BlockPaths = find_system('vdp','Type','Block')
BlockPaths = 
    'vdp/Fcn'
    'vdp/More Info'
    'vdp/More Info/Model Info'
    'vdp/Mu'
    'vdp/Mux'
    'vdp/Product'
    'vdp/Scope'
    'vdp/Sum'
    'vdp/x1'
    'vdp/x2'
    'vdp/Out1'
    'vdp/Out2'

Get a list of block dialog parameters for the Fcn block.

BlockDialogParameters = get_param('vdp/Fcn','DialogParameters')
BlockDialogParameters = 
                Expr: [1x1 struct]
          SampleTime: [1x1 struct]

Get the value for the Expr block parameter.

BlockParameterValue = get_param('vdp/Fcn','Expr')
BlockParameterValue =
    1 - u*u

Get a Block Parameter Value Using a Block Handle

If you make multiple calls to get_param for the same block, then using the block handle is more efficient than specifying the full block path as a string, e.g., 'vdp/Fcn'.

You can use the block handle in subsequent calls to get_param or set_param. If you examine the handle, you can see that it contains a double. Do not try to use the number of a handle alone (e.g., 5.007) because you usually need to specify many more digits than MATLAB® displays. Instead, assign the handle to a variable and use that variable name to specify a block.

Use getSimulinkBlockHandle to load the vdp model if necessary (by specifying true), and get a handle to the FCN block.

fcnblockhandle = getSimulinkBlockHandle('vdp/Fcn',true);

Use the block handle with get_param and get the value for the Expr block parameter.

BlockParameterValue = get_param(fcnblockhandle,'Expression')
BlockParameterValue =
    1 - u*u

Display Block Types for all Blocks in a Model

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

load_system('vdp')
BlockPaths = find_system('vdp','Type','Block')
BlockPaths = 
    'vdp/Fcn'
    'vdp/More Info'
    'vdp/More Info/Model Info'
    'vdp/Mu'
    'vdp/Mux'
    'vdp/Product'
    'vdp/Scope'
    'vdp/Sum'
    'vdp/x1'
    'vdp/x2'
    'vdp/Out1'
    'vdp/Out2'

Get the value for the BlockType parameter for each of the blocks in the vdp model.

BlockTypes = get_param(BlockPaths,'BlockType')
BlockTypes = 
    'Fcn'
    'SubSystem'
    'SubSystem'
    'Gain'
    'Mux'
    'Product'
    'Scope'
    'Sum'
    'Integrator'
    'Integrator'
    'Outport'
    'Outport'

Related Examples

Input Arguments

collapse all

Object — Name or handle of a model or block, or roothandle | string | cell array of strings | 0

Handle or name of a model or block, or root, specified as a numeric handle or a string, a cell array of strings for multiple blocks, or 0 for root. A numeric handle must be a scalar. You can also get parameters of lines and ports, but you must use numeric handles to specify them.

    Tip   If you make multiple calls to get_param for the same block, then specifying a block using a numeric handle is more efficient than using the full block path. Use getSimulinkBlockHandle to get a block handle. Do not try to use the number of a handle alone (e.g., 5.007) because you usually need to specify many more digits than MATLAB displays. Assign the handle to a variable and use that variable name to specify a block.

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/Fcn'

Parameter — Parameter of model or block, or rootstring

Parameter of model or block, or root, specified as a string or 0 for root. The table shows special cases.

Specified ParameterResult
'ObjectParameters'

Returns a structure array with the parameter names of the specified object (model, block, or root) as separate fields in the structure.

'DialogParameters'

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

Parameter name, e.g., 'BlockType'. Specify any model or block parameter, or block dialog box parameter.

Returns the value of the specified model or block parameter.

If you specified multiple blocks as a cell array, returns a cell array with the values of the specified parameter common to all blocks. All of the specified blocks in the cell array must contain the parameter, otherwise the function returns an error.

Example: 'ObjectParameters'

Data Types: char

Output Arguments

collapse all

ParamValue — The name or value of the specified parameter for the specified model or block, or rootany data type, depending on the parameter

The name or value of the specified parameter for the specified model or block, or root. If you specify multiple objects, the output is a cell array of objects. The table shows special cases.

Specified ParameterParamValue Returned
'ObjectParameters'

A structure array with the parameter names of the specified object (model, block, or root) as separate fields in the structure.

'DialogParameters'

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

Parameter name, e.g., 'BlockType'

The value of the specified model or block parameter. If multiple blocks are specified as a cell array, returns a cell array with the values of the specified parameter common to all blocks.

If you get the root parameters by specifying get_param(0,'ObjectParameters'), then the output ParamValue 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 string values that applies only to 'enum' parameter types

  • Attributes — Cell array of strings 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'

Was this topic helpful?