User`s manual

2 Creating C Language MEX-Files
2-4
Figure 2-1: C MEX Cycle
const mxArray *A
A = prhs[0]
MATLAB
A call to
MEX-file
func:
[C,D]=func(A,B)
tells MATLAB to
pass variables
A and
B to your MEX-file.
C and D are left
unassigned.
mxArray *C
C = plhs[0]
const mxArray *B
B = prhs[1]
mxArray *D
D = plhs[1]
INPUTS
OUTPUTS
func.c
void mexFunction(
int nlhs, mxArray *plhs[],
int nrhs, const mxArray *prhs[])
In the gateway routine:
Use the
mxCreate functions to create
the MATLAB arrays for your output
arguments. Set
plhs[0], [1], … to the
pointers to the newly created
MATLAB arrays.
Use the
mxGet functions to extract
your data from
prhs[0], [1], …
Call your C subroutine passing the
input and output data pointers as
function parameters.
MATLAB
On return from
MEX-file
func:
[C,D]=func(A,B)
plhs[0]
is assigned
to
C and plhs[1] is
assigned to
D.