get_param
Get parameter names and values
Description
returns the value value
= get_param(object
,parameter
)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
Get Block Parameter Value and 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 = 79×1 cell array {'AccelNoncompliantBlocksRatioLimit' } {'AutoAccelerationStepsPerBlockLimit' } {'AutoAccelerationStepsPerCodegenLimit' } . . . {'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 = struct with fields: Name: [1×1 struct] Tag: [1×1 struct] Description: [1×1 struct] Type: [1×1 struct] Parent: [1×1 struct] Handle: [1×1 struct] . . . ZeroInternalMemoryAtStartup: [1×1 struct]
Get the current value of the ModelVersion
model parameter for the
vdp
model.
ModelParameterValue = get_param('vdp','ModelVersion')
ModelParameterValue = '7.0'
Get List of Blocks and Parameter Value
Get a list of block paths and names for the blocks in the
sldemo_fuelsys
model. For one of the blocks, get a list
of block dialog parameters and the value of a block dialog parameter.
Open the Model a Fault-Tolerant Fuel Control System
example.
openExample('simulink_automotive/ModelingAFaultTolerantFuelControlSystemExample');
Get a list of block paths and names for all blocks in the top level of the
sldemo_fuelsys
model.
BlockPaths = get_param(gcs,'blocks')
BlockPaths = 21×1 cell array {'Callback Button' } {'Constant2' } {'Constant3' } {'Constant4' } {'Constant5' } {'Dashboard' } {'EGO Fault Switch' } {'Engine Gas Dynamics' } {'Engine Speed' } {'Engine Speed↵Fault Switch' } {'Engine_Speed_Selector' } {'MAP Fault Switch' } {'MAP_Selector' } {'O2_Voltage_Selector' } {'Scope' } {'Throttle↵Command' } {'Throttle Angle↵Fault Switch'} {'Throttle_Angle_Selector' } {'To Controller' } {'To Plant' } {'fuel_rate_control' }
The command outputs a list of block paths and names for all blocks in the top hierarchical level of the current system. If the current system is a subsystem, the command outputs a list of block paths and names for all blocks in the top hierarchical level of the subsystem.
In this example, the current system is sldemo_fuelsys
,
so the command outputs a list of block paths and names for all blocks in the
top hierarchical level of the sldemo_fuelsys
system.
Get a list of block paths and names for all blocks in all levels of the
sldemo_fuelsys
model.
BlockPaths = find_system(gcs,'Type','Block')
BlockPaths = 188×1 cell array {'sldemo_fuelsys/Callback Button' } {'sldemo_fuelsys/Constant2' } {'sldemo_fuelsys/Constant3' } ... {'sldemo_fuelsys/fuel_rate_control/fuel_rate' }
The command outputs a list of block paths and names for all blocks in the
top hierarchical level of the current system and in all lower levels of
model hierarchy that the current system contains. In this example, the
current system is sldemo_fuelsys
, so the output is a list
of block paths and names for all blocks in the
sldemo_fuelsys
model.
Get a list of block dialog parameters for the Gain block
named RT/Vm
. The first argument in the
get_param
function is the block path and name. Get
the block path and name from the BlockPaths
cell
array.
BlockDialogParameters = get_param(BlockPaths{44},'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(BlockPaths{44},'Multiplication')
BlockParameterValue = 'Element-wise(K.*u)'
Get Block Parameter Value Using Block Handle
Get the value of the Multiplication
block parameter of
the Gain block named Mu
in the
vdp
model.
Get the handle of the Gain block named
Mu
in the vdp
model using the
getSimulinkBlockHandle
function. Specify the model
and block names by entering 'vdp/Mu'
as the input
argument. If the vdp
model is not loaded, load the model
by specifying true
as the second input argument to the
getSimulinkBlockHandle
function.
mublockhandle = getSimulinkBlockHandle('vdp/Mu',true)
mublockhandle = 5.0001
The handle contains a double, for example, 5.0001
. If you display a
handle number in the MATLAB® Command Window, the display might not show all digits of the
number. Do not try to use this handle number by manually entering what you
see in the display. Instead, assign the handle to a variable and use that
variable name to specify the block.
Tip
If you make multiple calls to get_param
for the
same block, use the block handle instead of repeatedly specifying the
full block path as a character vector such as
'vdp/Mu'
. You can use the block handle in
subsequent calls to get_param
or
set_param
.
To get the value of the Multiplication
block parameter,
use the get_param
function. Specify the block handle as
the first input argument and the name of the block parameter as the second
input argument.
BlockParameterValue = get_param(mublockhandle,'Multiplication')
BlockParameterValue = 'Element-wise(K.*u)'
Display Block Types for All Blocks in 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 for Masked Parameter, Simulink Object, Block Diagram, or Annotation
You can retrieve the list of options for a parameter, Simulink object, block diagram, or annotation using the
get_param
function with the keyword
options
.
Get the list of options for a masked parameter. For example, consider the
masked Subsystem block in the ACSystem
model. Get the list of options for the Subsystem block
parameter Show port labels
.
openExample('simulink_masking/DesignAMaskDialogBoxExample') get_param('ACSystem/AC System','options@showportlabels')
ans = 1×4 cell array {'none'} {'FromPortIcon'} {'FromPortBlockName'} {'SignalName'}
Get the list of options for a block parameter. For example, get the list
of options for the Icon display
parameter of an
Inport block.
get_param('ACSystem/In1','options@icondisplay')
ans = 1×3 cell array {'Signal name'} {'Port number'} {'Port number and si…'}
Get Evaluated Value of Mask Parameter
You can access the evaluated value of a masked block parameter using the
get_param
function with the keyword
value
.
For example, consider the masked Subsystem block in the
ACSystem
model. Get the evaluated value of the
edit
parameter on the mask called Room Width
(W)
.
openExample('simulink_masking/DesignAMaskDialogBoxExample') get_param('ACSystem/AC System','value@W')
ans = 133
The option to retrieve the evaluated value is limited to mask parameters.
Open the mask of the AC System
block by double-clicking
the block. The value of the Room Width (W)
parameter is
the same as the value you get using the get_param
function.
Input Arguments
object
— Name, path, or handle of object or root
character vector | cell array of character vectors | string array | numeric scalar | 0
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 withget_param
. UsegetSimulinkBlockHandle
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
— Parameter, property, or attribute name
character vector | string scalar
Parameter, property, or attribute name, specified as a character vector or string scalar. Some names are case sensitive.
This table shows special cases.
Specified Parameter | Result |
---|---|
'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:
Models — See the configuration parameter reference pages.
Blocks — See Common Block Properties and block reference pages.
Ports — See the Signal Properties tool reference page.
Bus element port elements — See the In Bus Element and Out Bus Element block reference pages.
Example: 'ObjectParameters'
Example: 'Solver'
Example: 'SimulationCommand'
Example: 'Position'
Example: 'NameLocation'
Data Types: char
| string
Output Arguments
value
— Parameter value
format determined by parameter type
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 Parameter | Result |
---|---|
'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
Commande MATLAB
Vous avez cliqué sur un lien qui correspond à cette commande MATLAB :
Pour exécuter la commande, saisissez-la dans la fenêtre de commande de MATLAB. Les navigateurs web ne supportent pas les commandes MATLAB.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)