Main Content

get_param

Get parameter names and values

Description

example

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.

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

Examples

collapse all

Load the vdp model.

load_system('vdp');

Get the value for the Expression block parameter.

BlockParameterValue = get_param('vdp/Mu','Multiplication')
BlockParameterValue =

    'Element-wise(K.*u)'

Get the value for the SolverType model parameter.

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

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 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 a list of block paths and names for the vdp model.

load_system('vdp')
BlockPaths = find_system('vdp','Type','Block')
BlockPaths =

  14×1 cell array

    {'vdp/Constant'            }
    {'vdp/More Info'           }
    {'vdp/More Info/Model Info'}
    {'vdp/Mu'                  }
    {'vdp/Mux'                 }
    {'vdp/Product'             }
    {'vdp/Scope'               }
    {'vdp/Square'              }
    {'vdp/Sum'                 }
    {'vdp/Sum1'                }
    {'vdp/x1'                  }
    {'vdp/x2'                  }
    {'vdp/Out1'                }
    {'vdp/Out2'                }

Get a list of block dialog parameters for the Gain block named Mu.

BlockDialogParameters = get_param('vdp/Mu','DialogParameters')
BlockDialogParameters = 

  struct with fields:

                         Gain: [1×1 struct]
               Multiplication: [1×1 struct]
                     ParamMin: [1×1 struct]
                     ParamMax: [1×1 struct]
             ParamDataTypeStr: [1×1 struct]
                       OutMin: [1×1 struct]
                       OutMax: [1×1 struct]
               OutDataTypeStr: [1×1 struct]
                    LockScale: [1×1 struct]
                      RndMeth: [1×1 struct]
    SaturateOnIntegerOverflow: [1×1 struct]
                   SampleTime: [1×1 struct]

Get the value for the Multiplication block parameter.

BlockParameterValue = get_param('vdp/Mu','Multiplication')
BlockParameterValue =
    'Element-wise(K.*u)'

Get the value of a parameter of the Gain block named Mu in the vdp model

To get a handle to the Gain block named Mu, use the getSimulinkBlockHandle function. To load the vdp model, specify true.

mublockhandle = getSimulinkBlockHandle('vdp/Mu',true);

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 character vector, for example, 'vdp/Mu'.

You can use the block handle in subsequent calls to get_param or set_param. The handle contains a double. Do not try to manually enter the number of a handle, for example 5.007, because you usually need to specify more digits than MATLAB® displays. Instead, assign the handle to a variable and use that variable name to specify the block.

Use getSimulinkBlockHandle to load the vdp model if necessary by specifying true, and get a handle to the Gain block named Mu.

mublockhandle = getSimulinkBlockHandle('vdp/Mu',true);

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

BlockParameterValue = get_param(mublockhandle,'Multiplication')
BlockParameterValue =
    'Element-wise(K.*u)'

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

load_system('vdp')
BlockPaths = find_system('vdp','Type','Block')
BlockPaths =

  14×1 cell array

    {'vdp/Constant'            }
    {'vdp/More Info'           }
    {'vdp/More Info/Model Info'}
    {'vdp/Mu'                  }
    {'vdp/Mux'                 }
    {'vdp/Product'             }
    {'vdp/Scope'               }
    {'vdp/Square'              }
    {'vdp/Sum'                 }
    {'vdp/Sum1'                }
    {'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 =

  14×1 cell array

    {'Constant'  }
    {'SubSystem' }
    {'SubSystem' }
    {'Gain'      }
    {'Mux'       }
    {'Product'   }
    {'Scope'     }
    {'Math'      }
    {'Sum'       }
    {'Sum'       }
    {'Integrator'}
    {'Integrator'}
    {'Outport'   }
    {'Outport'   }

You can retrieve the list of options for a parameter, Simulink object, block diagram, or annotation using get_param with the keyword options.

Get the list of options for a masked parameter. For example, suppose you have a Gain block that is masked and has popup and combo box parameters.

get_param('vdp/Mu','options@Multiplication')
ans =

  1×4 cell array

    {'Element-wise(K.*u)'}  
  {'Matrix(K*u)'}    {'Matrix(u*K)'}    {'Matrix(K*u) (u vec…'}

Get the list of options for a block parameter, such as the ShowPortLabels parameter of a Subsystem block.

get_param(gcb,'options@showportlabels')
ans =
  1×4 cell array
    {'none'}    {'FromPortIcon'}    {'FromPortBlockName'}    {'SignalName'}

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

For example, get the evaluated value of an edit parameter of a masked Gain block.

get_param(gcb,'value@edit')
ans =
     4

The option to retrieve the evaluated value is limited to mask parameters.

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.

  • Bus element port element — Block path of model component with element label. The element can be any element of the port, such as a top-level bus, nested bus, signal, or message.

To specify multiple objects with a common parameter, use a cell array of character vectors, a string array, or an array of handles. All the specified objects must have the specified parameter, otherwise, the function returns an error.

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.

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