MATLAB Function

Include MATLAB code in models that generate embeddable C code (HDL Coder)

Description

The MATLAB Function block is available with Simulink®.

For information about the simulation behavior and block parameters, see MATLAB Function in Simulink documentation.

HDL Block Properties

ConstMultiplierOptimization

Canonical signed digit (CSD) or factored CSD optimization. The default is none. See also ConstMultiplierOptimization.

ConstrainedOutputPipeline

Number of registers to place at the outputs by moving existing delays within your design. Distributed pipelining does not redistribute these registers. The default is 0. See also ConstrainedOutputPipeline.

DistributedPipelining

Pipeline register distribution, or register retiming. The default is off. See also DistributedPipelining.

InputPipeline

Number of input pipeline stages to insert in the generated code. Distributed pipelining and constrained output pipelining can move these registers. The default is 0. See also InputPipeline.

InstantiateFunctions

Generate a VHDL® entity or Verilog® module for each function. The default is off. See also InstantiateFunctions.

LoopOptimization

Unroll, stream, or do not optimize loops. The default is none. See also LoopOptimization.

MapPersistentVarsToRAM

Map persistent arrays to RAM. The default is off. See also MapPersistentVarsToRAM.

OutputPipeline

Number of output pipeline stages to insert in the generated code. Distributed pipelining and constrained output pipelining can move these registers. The default is 0. See also OutputPipeline.

ResetType

Suppress reset logic generation. The default is default, which generates reset logic. See also ResetType.

SharingFactor

Number of functionally equivalent resources to map to a single shared resource. The default is 0. See also Resource Sharing.

UseMatrixTypesInHDL

Generate 2-D matrices in HDL code. The default is off. See also UseMatrixTypesInHDL.

VariablesToPipeline

Insert a pipeline register at the output of the specified MATLAB® variable or variables. Specify the list of variables as a character vector, with spaces separating the variables.

Complex Data Support

This block supports code generation for complex signals.

See also Complex Data Type Support.

Tunable Parameter Support

HDL Coder™ supports both tunable and non-tunable parameters with the following data types:

  • Scalar

  • Vector

  • Complex

  • Structure

  • Enumeration

When using tunable parameters with the MATLAB Function block:

  • The tunable parameter should be a Simulink.Parameter object with the StorageClass set to ExportedGlobal.

    x = Simulink.Parameter 
    x.Value = 1 
    x.CoderInfo.StorageClass = 'ExportedGlobal' 

  • In the Ports and Data Manager dialog box, select the tunable check box.

For details, see Generate DUT Ports for Tunable Parameters.

Restrictions

  • If the block contains a System object™, block inputs cannot have non-discrete (constant or Inf) sample time.

  • HDL Coder does not support a MATLAB Function that contains the same variable as the input and output of the function. For example, this MATLAB code is not supported.

    function y = myFun(y)
    %#codegen
    
    y = 3 * y;

For the MATLAB language subset supported for HDL code generation from a MATLAB Function block, see:

Was this topic helpful?