Main Content

MATLABFunctionConfiguration

MATLAB Function block property configuration

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 Block 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 character vector.

Data Types: char

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

Data Types: 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.

UI Use

In the Ports and Data Manager, set Update method to Inherited, Discrete, or Continuous

Data Types: enumerated

Sample time of the MATLAB Function block, specified as a 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.

UI Use

In the Ports and Data Manager, enter a value for the Sample Time parameter.

Data Types: char

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

UI Use

In the Ports and Data Manager, enter a description in the Description box.

Data Types: char

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

UI Use

In the Ports and Data Manager, enter a link in the Document link box.

Data Types: char

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

UI Use

In the Ports and Data Manager, select Support variable-size arrays to enable this setting.

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 is considered to have 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.

UI Use

In the Ports and Data Manager, select Allow direct feedthrough to enable this setting.

Data Types: logical

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.

UI Use

In the Ports and Data Manager, select Saturate on integer overflow to enable 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 fi Object Properties (Fixed-Point Designer).

UI Use

In the Ports and Data Manager, set Treat these inherit Simulink signal types as fi objects to Fixed-point or Fixed-point and & Integer.

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).

UI Use

In the Ports and Data Manager, set MATLAB Function fimath to Same as MATLAB or Specify Other.

Data Types: enumerated

Default fimath object, specified as a 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).

UI Use

In the Ports and Data Manager, set MATLAB Function fimath to Specify Other and enter a fimath expression.

Data Types: 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 Create Custom Functionality Using MATLAB Function Block.

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_block1 described in Create Custom Functionality Using MATLAB Function Block.

config = get_param('call_stats_block1/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
Introduced in R2019b