get_param
Get parameter names and values
Description
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:
Examples
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/Mu','Multiplication')
BlockParameterValue = 'Element-wise(K.*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 Blocks and a Parameter Value
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)'
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 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)'
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 = 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' }
Get list of options of a masked parameter, Simulink object, block diagram, and annotations
You can retrieve the list of options for a parameter, Simulink object, block
diagram, and annotations using get_param
with the keyword
options
.
Get list of options of a masked parameter
Consider an example where a Gain
block is masked and has a
popup
and combo box
parameters.
Use this code to retrieve the list of options.
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 option in any Simulink object, block diagram, and annotations
Consider an example with a Subsystem
block. You can retrieve
the options of any object in the block.
get_param(gcb,'options@showportlabels')
ans = 1×4 cell array {'none'} {'FromPortIcon'} {'FromPortBlockName'} {'SignalName'}
Get evaluated value of a masked parameter
You can access the evaluated value of the masked block parameter using the
get_param
command with keyword value.
Consider an example where a Gain
block is masked and has an
edit parameter.
get_param(gcb,'value@edit')
ans = 4
Note
The option to retrieve the evaluated value is limited to mask parameters