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 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 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 a Block Parameter Value Using a Block Handle
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)'
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 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 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'}
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, 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
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
Comando de MATLAB
Ha hecho clic en un enlace que corresponde a este comando de MATLAB:
Ejecute el comando introduciéndolo en la ventana de comandos de MATLAB. Los navegadores web no admiten comandos de 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)