Get parameter names and values
returns
the name or value of the specified parameter for the specified model
or block object. Open or load the Simulink® model first. ParamValue
= get_param(Object
,Parameter
)
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:
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 Mu
block.
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)'
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, e.g., 'vdp/Mu'
.
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 Mu
block.
mublockhandle = getSimulinkBlockHandle('vdp/Mu',true);
Use the block handle with get_param
and
get the value for the Expr
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' }
Object
— Name or handle of a model or block, or rootHandle or name of a model or block, or root, specified as a
numeric handle or a character vector, a cell array of character vectors
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/Mu'
Parameter
— Parameter of model or block, or rootParameter of model or block, or root, specified as a character
vector or 0
for root. The table shows special cases.
Specified Parameter | Result |
---|---|
'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
ParamValue
— The name or value of the specified parameter for the specified model or block, or rootThe 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 Parameter | ParamValue 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 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'
bdroot
| find_system
| gcb
| gcs
| getSimulinkBlockHandle
| set_param