This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.


Package: coder

Declare extrinsic function or functions



coder.extrinsic('function_name_1', ... , 'function_name_n');

coder.extrinsic('-sync:on', 'function_name');

coder.extrinsic('-sync:on', 'function_name_1', ... , 'function_name_n');


coder.extrinsic('-sync:off', 'function_name_1', ... , 'function_name_n');


function_name_1, ... , function_name_n

Declares function_name or function_name_1 through function_name_n as extrinsic functions.


function_name or function_name_1 through function_name_n.

Enables synchronization of global data between MATLAB® and MEX functions before and after calls to the extrinsic functions, function_name or function_name_1 through function_name_n. If only a few extrinsic calls modify global data, turn off synchronization before and after all extrinsic function calls by setting the global synchronization mode to At MEX-function entry and exit. Use the –sync:on option to turn on synchronization for only the extrinsic calls that do modify global data.


Disables synchronization of global data between MATLAB and MEX functions before and after calls to the extrinsic functions, function_name or function_name_1 through function_name_n. If most extrinsic calls modify global data, but a few do not, you can use the –sync:off option to turn off synchronization for the extrinsic calls that do not modify global data.


coder.extrinsic declares extrinsic functions. During simulation, the code generator produces code for the call to an extrinsic function, but does not produce the function's internal code. Therefore, simulation can run only on platforms where MATLAB software is installed. During standalone code generation, MATLAB attempts to determine whether the extrinsic function affects the output of the function in which it is called — for example by returning mxArrays to an output variable. Provided that there is no change to the output, MATLAB proceeds with code generation, but excludes the extrinsic function from the generated code. Otherwise, compilation errors occur.

You cannot use coder.ceval on functions that you declare extrinsic by using coder.extrinsic.

coder.extrinsic is ignored outside of code generation.


  • Extrinsic function calls have some overhead that can affect performance. Input data that is passed in an extrinsic function call must be provided to MATLAB, which requires making a copy of the data. If the function has any output data, this data must be transferred back into the MEX function environment, which also requires a copy.


  • The code generator detects calls to many common visualization functions, such as plot, disp, and figure. The software treats these functions like extrinsic functions, but you do not have to declare them extrinsic using the coder.extrinsic function.

  • Use the coder.screener function to detect which functions you must declare extrinsic. This function opens the code generations readiness tool that detects code generation issues in your MATLAB code.


The following code declares the MATLAB function patch as extrinsic in the MATLAB local function create_plot.

function c = pythagoras(a,b,color) %#codegen
% Calculates the hypotenuse of a right triangle
%  and displays the triangle as a patch object. 

c = sqrt(a^2 + b^2);

create_plot(a, b, color);

function create_plot(a, b, color)

%Declare patch as extrinsic

x = [0;a;a];
y = [0;0;b];
patch(x, y, color);

By declaring patch as extrinsic, you instruct the code generator not to compile or produce code for patch. Instead, the code generator dispatches patch to MATLAB for execution.

Introduced in R2011a

Was this topic helpful?