coder.extrinsic
Declare function as extrinsic and execute it in MATLAB
Syntax
Description
coder.extrinsic(
declares
function
)function
as an extrinsic function. The code generator does not
produce code for the body of the extrinsic function and instead uses the MATLAB® engine to execute the call. This functionality is available only when the
MATLAB engine is available during execution. Examples of situations where the
MATLAB engine is available include execution of MEX functions, Simulink® simulations, and function calls at the time of code generation (also known
as compile time).
During the generation of standalone code, the code generator attempts to determine whether the extrinsic function affects the function in which it is called. If the extrinsic function does not affect the calling function (for example, the extrinsic function displays a plot), the code generator proceeds with code generation, but excludes the extrinsic function from the generated code. If the extrinsic function affects the calling function (for example, the extrinsic function returns a value to the calling function), the code generator produces a compilation error.
MATLAB ignores the coder.extrinsic
directive outside of code
generation.
See Use MATLAB Engine to Execute a Function Call During Fixed-Point Algorithm Acceleration.
Note
The run-time output of an extrinsic function is an mxArray
,
also known as a MATLAB array. The only valid operations for an mxArray
are
storing it in a variable, passing it to another extrinsic function, or returning it to
MATLAB. To perform any other operation on an
mxArray
value, such as using it in an expression in your code,
you must convert the mxArray
to a known type by assigning the
mxArray
to a variable whose type is already defined by a prior
assignment. See Working with mxArrays (MATLAB Coder).
coder.extrinsic(function1,...,functionN)
declares
function1
through functionN
as extrinsic
functions.
coder.extrinsic(
controls synchronization of global data between your MATLAB code and the generated MEX file before and after the extrinsic function
call. By default, the code generator synchronizes global variables before and after
extrinsic function calls to maximize consistency between the MATLAB code and the MEX function. To learn how and when to change this default
behavior, see Generate Code for Global Data (MATLAB Coder).syn
, function1, ... ,functionN)
Examples
Input Arguments
Limitations
You cannot use
coder.ceval
(MATLAB Coder) on functions that you declare as extrinsic by usingcoder.extrinsic
.Extrinsic function calls can affect performance, because the code generator copies the data that you pass to an extrinsic function and sends the data to MATLAB for execution. Conversely, MATLAB copies any output data for transfer back into the MEX function environment.
The code generator does not support the use of
coder.extrinsic
to call functions that are located in a private folder.The code generator does not support the use of
coder.extrinsic
to call local functions.Code generation does not support values passed to or returned from extrinsic functions that are or contain:
Handle classes
Function handles
Opaque values (See
coder.opaque
(MATLAB Coder).)
Tips
The code generator automatically treats many common MATLAB visualization functions, such as
plot
,disp
, andfigure
, as extrinsic. You do not have to explicitly declare these functions as extrinsic by usingcoder.extrinsic
.Use the
coder.screener
(MATLAB Coder) function to detect which functions you must declare as extrinsic. This function runs the Code Generation Readiness Tool, which screens your MATLAB code for features and functions that are not supported for code generation. See Check Code Using the Code Generation Readiness Tool.
Extended Capabilities
Version History
Introduced in R2011a