Programmatically Specify Block Parameters and Properties
Block parameters typically define model dynamics and mathematics. They also let you configure the appearance of the block. Whether a block has parameters that you can set and the nature of those parameters is specific to each block.
Block properties typically describe fundamental block characteristics and help determine when the block executes. Block properties include block annotations, callbacks that execute when a block event occurs, execution order priority, and tags that help identify the block.
To write scripts that create and modify models, use the get_param
and set_param
functions to query and modify block
property and parameter values. For example, suppose you have a Gain block in a
model named mymodel
.
This command sets the
Gain
parameter of the Gain block to2
.set_param("mymodel/Gain",Gain="2")
This command orients the Gain block to the left. By default, the block faces the opposite direction.
set_param("mymodel/Gain",Orientation="left")
This command associates an
OpenFcn
callback with the Gain block.set_param("mymodel/Gain",OpenFcn="my_open_cb")
This command sets the
Position
property of the Gain block. The block is 75 pixels wide by 25 pixels high.set_param("mymodel/Gain",Position=[50 250 125 275])
For background information on programmatic modeling, see Programmatic Modeling Basics.
For information about how to specify paths that contain multiline names or special characters, see Specify Paths That Contain Multiline Names and Special Characters.
Block-Specific Parameters
Most block-specific parameters are documented on the page that documents the block. For example, the parameters of the Gain block are documented on the Gain block reference page. For programmatic information on a parameter, expand the corresponding parameter entry on the block reference page.
For a script that gets and sets the values of the block-specific parameters, select a
block and open the Property Inspector.
In the Property Inspector, click Script Reference. The
script gets the parameter values with the get_param
function and sets the
parameter values with the set_param
function. If you change the value of
a parameter, the script updates to reflect the new value.
To get a list of programmatic block parameters, select a block. Then, query one of these
properties with the get_param
function.
DialogParameters
— Block-specific parameters for an unmasked block, or mask parameters for a masked block.IntrinsicDialogParameters
— Block-specific parameters for masked or unmasked blocks.ObjectParameters
— Block-specific parameters and common block properties.
Some of the returned parameters and properties can be for internal use only. When a block property or parameter is undocumented, consider that parameter to be for internal use only.
Common Block Properties
A common property of Simulink® objects is the read-only Type
property. For blocks, this
property returns 'block'
.
Each block has a block type. For some blocks, the block type is the same as the block name
in the Library Browser. For example, the block type of a Gain
block is Gain
. For other blocks, the block type differs from the block name
in the Library Browser. For example, the block type of an Add
block is Sum
.
To get the block type for blocks without a mask, query the read-only
BlockType
property with theget_param
function.To get the block type for blocks with a mask, query the
MaskType
property with theget_param
function. Typically, masked blocks have aBlockType
ofSubSystem
.
For information about the properties of a masked block, see Mask Parameters.
For information about block callback properties, see Block Callbacks.
These tables list additional properties common to Simulink blocks.
Common Block Properties: Names and Handles
Property | Description | Values |
---|---|---|
| Numeric block handle. Assign the handle to a variable and use that variable name to specify the block. The handle applies to only the current MATLAB® session. | double number |
| Names of input signals. | cell array |
| Handles of lines connected to block. Assign a line handle to a variable and use that variable name to specify the line. The handle applies to only the current MATLAB session. | structure |
| Block or signal name. To specify a signal name, use the corresponding port or line handle. ports = get_param(gcb,"PortHandles"); out1 = ports.Outport(1); set_param(out1,Name="NewName"); To propagate the signal name, compile the model. set_param(gcs,SimulationCommand="update"); Alternatively,
to name an output signal of a block, use
| character vector |
| Names of output signals. | cell array |
| Name of the system that owns the block. | character vector |
| Handles of the block ports. Assign a port handle to a variable and use that variable name to specify the port. The handle applies to only the current MATLAB session. The structure has these fields:
| structure array |
Common Block Properties: Ports
Property | Description | Values |
---|---|---|
| Returns whether the port connects to a virtual bus or nonvirtual bus. To get compiled information about the port, use the corresponding port or line handle and compile the model. ports = get_param(gcb,"PortHandles"); out1 = ports.Outport; feval(gcs,[],[],[],"compile"); bt = get_param(out1,"CompiledBusType") feval(gcs,[],[],[],"term"); |
|
| Complexity of port signals after updating diagram. To get compiled information about the ports, compile the model. feval(gcs,[],[],[],"compile"); cs = get_param(gcb,"CompiledPortComplexSignals") feval(gcs,[],[],[],"term"); | structure array |
| Data types of port signals after updating diagram. To get compiled information about the ports, compile the model. feval(gcs,[],[],[],"compile"); dt = get_param(gcb,"CompiledPortDataTypes") feval(gcs,[],[],[],"term"); | structure array |
| Design minimum of port signals after updating diagram. To get compiled information about the port, use the corresponding port or line handle and compile the model. ports = get_param(gcb,"PortHandles"); out1 = ports.Outport; feval(gcs,[],[],[],"compile"); min = get_param(out1,"CompiledPortDesignMin") feval(gcs,[],[],[],"term"); | structure array |
| Design maximum of port signals at compile time. To get compiled information about the port, use the corresponding port or line handle and compile the model. ports = get_param(gcb,"PortHandles"); out1 = ports.Outport; feval(gcs,[],[],[],"compile"); max = get_param(out1,"CompiledPortDesignMax") feval(gcs,[],[],[],"term"); | structure array |
| Dimensions of port signals after updating diagram. To get compiled information about the port, use the corresponding port or line handle and compile the model. ports = get_param(gcb,"PortHandles"); out1 = ports.Outport; feval(gcs,[],[],[],"compile"); d = get_param(out1,"CompiledPortDimensions") feval(gcs,[],[],[],"term"); For details, see Get Compiled Port Dimensions. | numeric array |
| Indication of whether the port signal has a variable size after updating
diagram. To get compiled information about the port, use the corresponding port or line handle and compile the model. ports = get_param(gcb,"PortHandles"); out1 = ports.Outport; feval(gcs,[],[],[],"compile"); dm = get_param(out1,"CompiledPortDimensionsMode") feval(gcs,[],[],[],"term"); | double number |
| Frame mode of port signals after updating diagram. To get compiled information about the port, use the corresponding port or line handle and compile the model. ports = get_param(gcb,"PortHandles"); out1 = ports.Outport; feval(gcs,[],[],[],"compile"); fd = get_param(out1,"CompiledPortFrameData") feval(gcs,[],[],[],"term"); | structure array |
| Structure array of block port units after updating diagram. To get compiled information about the port, compile the model. feval(gcs,[],[],[],"compile"); units = get_param(gcb,"CompiledPortUnits") feval(gcs,[],[],[],"term"); | structure array |
| Structure of port widths after updating diagram. To get compiled information about the port, compile the model. feval(gcs,[],[],[],"compile"); units = get_param(gcb,"CompiledPortWidths") feval(gcs,[],[],[],"term"); | structure array |
| Block paths to objects that are connected to the Viewers and Generators Manager. The software saves these paths when the model is saved. | list |
| Array of structures, each of which describes one of the block input or output ports. Each port structure has these fields:
| structure array |
| Type of port rotation used by this block. |
|
| Number of each kind of port this block has. The order of the elements in the returned vector corresponds to these port types:
| vector |
| If the signal is a bus, returns the name and hierarchy of the elements in the bus. To get the signal hierarchy, use the corresponding port or line handle and compile the model. ports = get_param(gcb,"PortHandles"); out1 = ports.Outport; feval(gcs,[],[],[],"compile"); sh = get_param(out1,"SignalHierarchy") feval(gcs,[],[],[],"term"); | values that reflect the structure of the signal |
Common Block Properties: Behavior
Property | Description | Values |
---|---|---|
Commented | Exclude block from simulation. |
|
| Specifies whether the block status is active at compile time.
|
|
| Block sample time after updating diagram. To get the sample time, compile the model. feval(gcs,[],[],[],"compile"); ts = get_param(gcb,"CompiledSampleTime") feval(gcs,[],[],[],"term"); | vector or cell array of sample time and offset time, respectively |
| Indicates whether the block is a supported state owner block that can be used with the State Reader and State Writer blocks. |
|
| Enable a block to support uploading of signal data in external mode, for example, with a scope block. |
|
| Enable a block to act as the trigger block for external mode signal uploading. |
|
ExtModeUploadOption | Enable a block to upload signal data in external mode when the Select
all check box on the External Signal & Triggering dialog box is not
selected. A value of log indicates the block uploads signals. A
value of none indicates the block does not upload signals. The
value monitor is currently not in use. If the Select
all check box on the External Signal & Triggering dialog box is
selected, it overrides this parameter setting. | 'none' (default) | 'log' |
'monitor' |
| Status of whether or not block is selected. |
|
| State perturbation size to use during linearization. For details, see Change Perturbation Level of Blocks Perturbed During Linearization (Simulink Control Design). | character vector |
| Specifies the block order of execution relative to other blocks in the same model. Set by the Priority field on the General pane of the Block Properties dialog box. |
|
Common Block Properties: Appearance
Property | Description | Values |
---|---|---|
| Block background color. |
|
BlockMirror | Block mirror. |
|
BlockRotation | Block rotation angle. For 0 degrees rotation, the value is
| double number |
| Display drop shadow. |
|
| Font angle. |
|
| Font name. | character array |
| Font size. A value of |
|
| Font weight. |
|
| Foreground color of block icon. The value changes if it is too
similar to the canvas color specified by the |
|
| Specify whether the block name given automatically by the Simulink Editor displays in the model. For information on using this parameter, see Hide or Display Block Names. |
|
| Position of block name. |
|
| Direction block faces. |
|
| Position of block in model window. The origin is the upper-left corner of the Simulink Editor canvas before any canvas resizing. Supported coordinates are between -1073740824 and 1073740823, inclusive. Positive values are to the right of and down from the origin. Negative values are to the left of and up from the origin. To help with block alignment, the position you set can differ
from the actual block position by a few pixels. To return the actual position, use
the | vector of coordinates, in pixels: |
| Display or hide block name. For information on using this parameter, see Hide or Display Block Names. |
|
Common Block Properties: Metadata
Property | Description | Values |
---|---|---|
| Block annotation text that corresponds to block properties. | character vector |
| Block description shown at the top of the block parameters dialog box or property inspector. | character array |
| Description of block. Set by the Description field in the General pane of the Block Properties dialog box. | text and tokens |
| User specified data, used by Simulink Coder™ software. Intended only for use with user written S-functions. For details, see S-Function RTWdata (Simulink Coder). | structure of character vectors |
| Text that appears in the block label that Simulink software generates. Set by the Tag field on the General pane of the Block Properties dialog box. |
|
| User-specified data that can have any MATLAB data type. |
|
| Status of whether or not |
|
Common Block Properties: Libraries
Property | Description | Values |
---|---|---|
| Name of the library block that the block is linked to for blocks with a disabled link. | character vector |
BlockKeywords | Associates one or more keywords with a custom library block. | character vector | string scalar | string array |
| For a linked block, the initial value of this property is the
ModelVersion of the library at the time the link was created. The
value updates with increments in the model version of the library. |
|
| Array of details about changes to the blocks inside the link that differ
between a parameterized link and its library, listing the block names and parameter
values. Use | cell array |
| Link status of block. Updates out-of-date linked blocks when queried using
the |
|
| Name of the library block to which this block links. |
|
| Link status of block. Does not update out-of-date linked blocks when
queried using the | 'none' | 'resolved' |
'unresolved' | 'implicit' |
'inactive' | 'restore' |
'propagate' | 'propagateHierarchy' |
'restoreHierarchy' |
Some common block properties are for internal use only. For example, these properties are for internal use only:
DataTypeOverride_Compiled
Diagnostics
HiliteAncestors
IOType
MinMaxOverflowLogging_Compiled
ModelParamTableInfo
RequirementInfo
Maximum Size Limits for Block Parameter Values
For block parameters that accept array values, the number
of elements in the array cannot exceed what int_T
can represent. This
limitation applies to both simulation and Simulink
Coder code generation.
The maximum number of characters that a parameter edit field can contain is 49,000.