Main Content

MATLABFunctionConfiguration

MATLAB Function block property configuration

Since R2019b

Description

The MATLABFunctionConfiguration object controls the MATLAB Function block properties such as the description, sample time, and function script.

Tip

You can also configure a MATLAB® Function block programmatically by using a Stateflow.EMChart object. This object provides access to the inputs, outputs, and properties of a MATLAB Function block. For more information, see Configure MATLAB Function Blocks Programmatically.

Creation

Each MATLAB Function block has its own MATLABFunctionConfiguration object. To access this object, use the get_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

expand all

Path of the MATLAB Function block relative to the model, specified as a string scalar or character vector.

Data Types: string | char

Code for the MATLAB Function block, specified as a string scalar or character vector.

Data Types: string | char

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. If UpdateMethod 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 the SampleTime 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 the UpdateMethod is changed to "Continuous", Sample Time is automatically set to 0.

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

Sample time of the MATLAB Function block, specified as a string scalar or character vector. Sample time is only valid when UpdateMethod is set to "Discrete". If UpdateMethod is set to "Continuous" or "Inherited", any changes made to the sample time are ignored.

Data Types: string | char

Description of the MATLAB Function block, specified as a string scalar or character vector.

Data Types: string | char

Documentation link for the MATLAB Function block, specified as a string scalar or character vector.

Data Types: string | char

Whether the MATLAB Function block supports variable-size data, specified as a numeric or logical 1 (true) or 0 (false).

Data Types: logical

Whether the MATLAB Function block supports direct feedthrough semantics, specified as a numeric or logical 1 (true) or 0 (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.

Data Types: logical

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

Since R2023a

Whether MATLAB Function block output variables with at least one dimension of length 1 are fixed size, specified as a numeric or logical 0 (false) or 1 (true). When this property is true, the object sets variables that are variable size in the block with a dimension of 1 to fixed size. When this property is false, variables in the block that have the Variable size property enabled are always variable size. Prior to R2023a, the object treats variables with at least one dimension of length 1 as fixed size.

This property only affects output variables that have the Variable size property enabled. See Variable size.

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 is false, 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

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 as fi objects.

  • "FixedPointAndInteger" — The MATLAB Function block treats all fixed-point and integer inputs as fi objects.

To learn more about fi objects, see Set fi Object Properties (Fixed-Point Designer).

Data Types: enumerated

Default fimath properties for the MATLAB Function block, specified as one of these values:

  • "SameAsMATLAB" — Use the same fimath properties as the current default fimath object.

  • "UserSpecified" — Use the Fimath property to specify the default fimath object.

To learn more about fixed-point math, see fimath (Fixed-Point Designer).

Data Types: enumerated

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

openReportOpen MATLAB function report
closeReportClose MATLAB function report
getReportGenerate MATLAB function report

Examples

collapse all

Access the MATLABFunctionConfiguration object for the MATLAB Function block in the model call_stats_block1 described in Implement 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.";

Access the MATLABFunctionConfiguration object for the MATLAB Function block in the model call_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:
1. mean -- Output
2. stdev -- Output
3. vals -- Input
4. len -- Local

Function avg uses these variables:
1. mean -- Output
2. array -- Input
3. size -- Input

Version History

Introduced in R2019b

expand all