Step | Action | Details |
---|---|---|
1 | Install prerequisite products. | Installing Prerequisite Products |
2 | Set up your file infrastructure. | Paths and File Infrastructure Setup |
3 | Fix errors detected by the code analyzer. | Fixing Errors Detected at Design Time |
4 | Specify build configuration parameters. | Specify Build Configuration Parameters |
5 | Specify properties of primary function inputs. | Specify Properties of Entry-Point Function Inputs |
6 | Generate the MEX function using | codegen |
In this example, you use the codegen
function
to generate a MEX function from a MATLAB® file that adds two inputs.
You use the codegen
-args
option
to specify that both inputs are int16
.
In a local writable folder, create a MATLAB file, mcadd.m
,
that contains:
function y = mcadd(u,v) %#codegen y = u + v;
Generate a platform-specific MEX function in the current
folder. At the command line, specify that the two input parameters
are int16
using the -args
option.
By default, if you do not use the -args
option, codegen
treats
inputs as real, scalar doubles.
codegen mcadd -args {int16(0), int16(0)}
codegen
generates a MEX function, mcadd_mex
,
in the current folder. codegen
also generates
other supporting files in a subfolder called codegen/mex/mcadd
.codegen
uses
the name of the MATLAB function as the root name for the generated
files and creates a platform-specific extension for the MEX file,
as described in Naming Conventions.