Function Definition
There are special considerations when you create MATLAB® functions that are intended for fixed-point
acceleration. These include certain restrictions when you use
varargin and
varargout, recursive functions, anonymous
functions, and nested functions. To generate code for
MATLAB recursive functions, the code generator uses
either compile-time recursion or run-time recursion. To produce
efficient C/C++ code, the code generator sometimes creates
multiple versions of a function, referred to as function
specializations. In certain cases, you can prevent the code
generator from creating function specializations using coder.ignoreConst (MATLAB Coder).
While generating a MEX function, you can bypass code generation
for a specific function in your MATLAB code and instead use the MATLAB engine to execute the call. To do this, use the
coder.extrinsic construct.
Functions
coder.extrinsic | Declare function as extrinsic and execute it in MATLAB |
coder.ignoreConst | Prevent use of constant value of expression for function specializations |
coder.mustBeConst | Validate that value is a compile-time constant (Since R2023b) |
coder.unroll | Unroll for-loop by making a copy of
the loop body for each loop iteration |
coder.sameSizeBinaryOp | Apply element-wise binary operations without implicit expansion (Since R2021b) |
coder.noImplicitExpansionInFunction | Disable implicit expansion within the specified function in the generated code (Since R2021b) |
coder.read | Read data files at run time in generated code (Since R2023a) |
coder.write | Create data files that the generated code reads at run time (Since R2023a) |
Troubleshooting
Resolve Error: Arrays Have Incompatible Sizes (MATLAB Coder)
Troubleshoot size incompatibility errors that occur during code generation.
Resolve Error: Fixed Size on the Left Side but Variable Size on the Right (MATLAB Coder)
Troubleshoot errors when assigning variable-size arrays to fixed-size arrays.
Resolve Error: coder.varsize Not Supported for Strings (MATLAB Coder)
Troubleshoot code generation error when using coder.varsize
with string variables.
Resolve Error: coder.varsize Not Supported for Class Properties (MATLAB Coder)
Troubleshoot code generation error when using coder.varsize
with properties of a MATLAB class.
Resolve Error: Unable to Produce Column Vector from Scalar (MATLAB Coder)
Troubleshoot error when an input argument that is a variable-length column vector at code generation time is a scalar at run time.
Resolve Error: Incorrect Size for Expression (MATLAB Coder)
Troubleshoot MEX function error when the size of an array at run time is incompatible with the size of the array in the generated code.