Parametrize a MATLAB function so that it works in MATLAB or in generated code. When the function runs in MATLAB, it calls the MATLAB function myabsval
. The generated code, however, calls a
C library function myabsval
.
Write a MATLAB function
myabsval
.
Generate a C static library for myabsval
, using the
-args
option to specify the size, type, and complexity of the input
parameter.
The
codegen
function creates the library file
myabsval.lib
and header file
myabsval.h
in the
folder
\codegen\lib\myabsval
. (The library file extension can change
depending on your platform.) It generates the functions
myabsval_initialize
and
myabsval_terminate
in
the same folder.
Write a MATLAB function to call the generated C library function using
coder.ceval
.
Generate the MEX function callmyabsval_mex
. Provide the
generated library file at the command line.
Rather than providing the library at the command line, you can use coder.updateBuildInfo
to specify the
library within the function. Use this option to preconfigure the build. Add this line to
the else
block:
Run the MEX function callmyabsval_mex
which calls the library
function
myabsval
.
Call the MATLAB function
callmyabsval
.
The
callmyabsval
function exhibits the desired behavior for execution
in MATLAB and in code generation.