Resolve Error: Function Is Not Supported for Code Generation
Certain MATLAB® functions are not supported for code generation. If you try to generate code for these unsupported functions, you see this error message:
The function <function_name> is not supported for code generation.
This error message occurs when the code generator cannot generate code for the specified function. If you want to generate code for your project, use the following workarounds depending on your deployment platform.
MEX Target: Declare the Function as Extrinsic
To call the unsupported function in a MEX, declare the function as an extrinsic in your
MATLAB code. The function bypasses code generation and instead uses the MATLAB engine to execute the call. This functionality is available only when the
MATLAB engine is available in MEX functions. Certain functions are automatically marked
as extrinsic while other functions require you to explicitly call them as an extrinsic
function. To declare a function as an extrinsic function, use
coder.extrinsic. For more information, see Use MATLAB Engine to Execute a Function Call in Generated Code.
Standalone Target: Manually Implement the Function in MATLAB Code or C/C++ Code
To generate standalone code for a project that uses unsupported functions, manually implement the unsupported function as custom MATLAB code that is supported for code generation or C/C++ code.
To use handwritten C/C++ code to implement the unsupported functionality, call this code
from inside your MATLAB code by using
coder.ceval. Then generate code for the
entry-point MATLAB functions as usual.
You can find third-party custom MATLAB code or C/C++ code for the function that you require.
Before using third-party custom MATLAB code, generate a MEX function for the code to verify that it performs as expected. Similarly with third-party C/C++ code, verify that the code or library performs as expected.
You can also deploy your MATLAB code to a platform that supports MATLAB Compiler™. The code generated by the compiler is not completely standalone as it requires access to MATLAB run-time libraries. See Write Deployable MATLAB Code (MATLAB Compiler).
Request Code Generation Support
MathWorks® is continually adding C/C++ code generation support for MATLAB built-in functions and toolbox functions. Submit a request to add code generation support for this function by filling out this form: Request Code Generation Support for MATLAB Functions.