MATLABFunctionConfiguration - MATLAB Function block property configuration - MATLAB (original) (raw)
MATLAB Function block property configuration
Description
The MATLABFunctionConfiguration
object controls the MATLAB Function block properties such as the description, sample time, and function script.
Creation
Each MATLAB Function block has its ownMATLABFunctionConfiguration
object. To access this object, use theget_param function. For example, if the model myModel
contains a MATLAB Function block called MATLAB Function
, enter:
config = get_param("myModel/MATLAB Function", ... "MATLABFunctionConfiguration");
Properties
Path
— Path of block relative to model
string scalar | character vector
Path of the MATLAB Function block relative to the model, specified as a string scalar or character vector.
Data Types: string
| char
FunctionScript
— Code for MATLAB Function block
string scalar | character vector
Code for the MATLAB Function block, specified as a string scalar or character vector.
Data Types: string
| char
UpdateMethod
— Update method for MATLAB Function block
"Inherited"
(default) | "Discrete"
| "Continuous"
Update method for the MATLAB Function block, specified as one of these values:
"Inherited"
— The input signal at the trigger port determines when the block is updated during a simulation. A signal from a connected Simulink® block triggers the port. IfUpdateMethod
is changed to"Inherited"
,Sample Time
is automatically set to-1
."Discrete"
— The Simulink model generates an implicit event at regular time intervals to awaken the block at the rate you specify in theSampleTime
property. Other blocks in the model can have different sample times."Continuous"
— The MATLAB Function block updates at major time steps only, although it computes outputs and local continuous variables during minor and major time steps. If theUpdateMethod
is changed to"Continuous"
,Sample Time
is automatically set to0
.
When you set UpdateMethod
to "Inherited"
or"Continuous"
and attempt to change SampleTime
, Simulink displays a warning and ignores the input sample time.
Data Types: enumerated
SampleTime
— Sample time
"-1"
(default) | "0"
| string scalar | character vector
Sample time of the MATLAB Function block, specified as a string scalar or character vector. This property applies only when theUpdateMethod
property is "Discrete"
.
Data Types: string
| char
Description
— Description
string scalar | character vector
Description of the MATLAB Function block, specified as a string scalar or character vector.
Data Types: string
| char
DocumentLink
— Documentation link
string scalar | character vector
Documentation link for the MATLAB Function block, specified as a string scalar or character vector.
Data Types: string
| char
SupportVariableSizing
— Whether MATLAB Function block supports variable-size data
true
or 1
(default) | false
or 0
Whether the MATLAB Function block supports variable-size data, specified as a numeric or logical 1
(true
) or 0
(false
). For more information, see Declare Variable-Size MATLAB Function Block Variables.
Data Types: logical
AllowDirectFeedthrough
— Whether MATLAB Function block supports direct feedthrough semantics
true
or 1
(default) | false
or 0
Whether the MATLAB Function block supports direct feedthrough semantics, specified as a numeric or logical 1
(true
) or0
(false
). The block has direct feedthrough if the output of the block directly depends on the input of the block. The block does not have direct feedthrough if the outputs of the block depend on the internal states and properties rather than the input of the block. For more information, see Use Nondirect Feedthrough in a MATLAB Function Block.
Data Types: logical
VectorOutputs1D
— Whether MATLAB Function block outputs column vectors as one-dimensional data
false
or 0
(default) | true
or 1
Since R2021b
Whether the MATLAB Function block outputs column vectors as one-dimensional data, specified as a numeric or logical 0
(false
) or 1
(true
). When enabled, the block converts vectors of size _N_-by-1 to one-dimensional signals with a signal size equal to N.
Data Types: logical
TreatDimensionOfLengthOneAsFixedSize
— Whether MATLAB Function block treats output variables with dimension of length 1 as fixed size
true
or 1
(default) | false
or 0
Since R2023a
Whether the MATLAB Function block treats output variables with a dimension of length 1 as fixed size, specified as a numeric or logical0
(false
) or 1
(true
). When this property is true
, theMATLAB Function block treats output variables that have at least one dimension of length 1 as fixed size, regardless of whether you specify the variables as having variable size. When this property is false
, the MATLAB Function block treats output variables as variable size if you specify the variables as having variable size. For more information, see Variable size.
SaturateonIntegerOverflow
— Whether data saturates on integer overflow
true
or 1
(default) | false
or 0
Whether the data in the MATLAB Function block saturates on integer overflow, specified as a numeric or logical 1
(true
) or 0
(false
). If this setting is set to true
, the overflows saturate to either the minimum or maximum value that the data type can represent. If the setting isfalse
, the overflow wraps to the appropriate value that the data type can represent. If your model has a possible overflow and you want to apply saturation protection in your generated code, it is recommended to enable this setting. If you have performance restrictions or are not concerned with integer overflow, you can disable this setting.
Data Types: logical
TreatAsFi
— Inherited signals to treat as fi
objects
"FixedPoint"
(default) | "FixedPointAndInteger"
Inherited Simulink signals to treat as Fixed-Point Designer™fi
objects, specified as one of these values:
"FixedPoint"
— The MATLAB Function block treats all fixed-point inputs asfi
objects."FixedPointAndInteger"
— The MATLAB Function block treats all fixed-point and integer inputs asfi
objects.
To learn more about fi
objects, see Set fi Object Properties (Fixed-Point Designer).
Data Types: enumerated
FimathMode
— Default fimath
properties
"SameAsMATLAB"
(default) | "UserSpecified"
Default fimath
properties for the MATLAB Function block, specified as one of these values:
"SameAsMATLAB"
— Use the samefimath
properties as the current defaultfimath
object."UserSpecified"
— Use theFimath
property to specify the defaultfimath
object.
To learn more about fixed-point math, see fimath (Fixed-Point Designer).
Data Types: enumerated
Fimath
— Default fimath
object
string scalar | character vector
Default fimath
object, specified as a string scalar or character vector. When the FimathMode
property for the MATLAB Function block is "UserSpecified"
, you can use this property to:
- Enter an expression that constructs a
fimath
object. - Enter the variable name for a
fimath
object in the MATLAB or model workspace.
To learn more about fimath
object properties, see fimath Object Properties (Fixed-Point Designer).
Data Types: string
| char
Object Functions
Examples
Configure MATLAB Function Block Properties
Access the MATLABFunctionConfiguration
object for the MATLAB Function block in the model call_stats_block1
described inImplement MATLAB Functions in Simulink with MATLAB Function Blocks.
config = get_param("call_stats_block1/MATLAB Function", ... "MATLABFunctionConfiguration");
Set the value of the Description
property.
config.Description = "Calculate the mean and standard deviation for a vector of values.";
Create Custom Report for MATLAB Function Block
Access the MATLABFunctionConfiguration
object for theMATLAB Function block in the modelcall_stats_block2
described in Implement MATLAB Functions in Simulink with MATLAB Function Blocks.
config = get_param("call_stats_block2/MATLAB Function", ... "MATLABFunctionConfiguration");
Create the MATLABFunctionReport
object for the MATLAB Function block.
report = getReport(config);
Access the coder.Function
objects in the report.
functions = report.Functions;
Create a custom report that lists the functions and variables in the MATLAB Function block.
for i = 1:numel(functions) fprintf("Function %s uses these variables:\n",functions(i).Name) variables = functions(i).Variables; for j = 1:numel(variables) fprintf("%d. %s -- %s\n",j,variables(j).Name,variables(j).Scope) end fprintf("\n") end
Function stats uses these variables:
- mean -- Output
- stdev -- Output
- vals -- Input
- len -- Local
Function avg uses these variables:
- mean -- Output
- array -- Input
- size -- Input
Version History
Introduced in R2019b
R2023a: Specify how to treat output variables with dimension of length 1
With the new property [TreatDimensionOfLengthOneAsFixedSize](simulink.matlabfunctionconfiguration.html#mw%5Fd1149f74-789d-4983-af86-cdf071b13d6c)
, you can specify how MATLAB Function blocks treat output variables when at least one dimension has length 1. Prior to R2023a, MATLAB Function blocks treat output variables with a dimension of length 1 as fixed size, regardless of whether you specify the variables as having variable size.
R2021b: Change to output column vectors
You can output column vectors in MATLAB Function blocks as two-dimensional or one-dimensional data with the VectorOutputs1D
property.
Before R2021b, MATLAB Function blocks always output column vectors as one-dimensional data. After R2021b, MATLAB Function blocks output column vectors as two-dimensional data by default. To maintain the original behavior of the block, set the VectorOutputs1D
property to true
.
R2021a: Programmatically access MATLAB function reports
You can access MATLAB function reports for MATLAB Function blocks by calling these functions on MATLABFunctionConfiguration
objects:
openReport
opens the MATLAB function report for the block.closeReport
closes the MATLAB function report for the block.getReport
returns aMATLABFunctionReport
object for the block. You can query report information from this object by accessing its'Functions'
property, which is an array ofcoder.Function
objects.