User`s manual
3 Creating Fortran MEX-Files
3-4
Figure 3-1: Fortran MEX Cycle
integer A
A = prhs(1)
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.
integer C
C = plhs(1)
integer B
B = prhs(2)
integer D
D = plhs(2)
INPUTS
OUTPUTS
func.f
subroutine mexFunction(
nlhs, plhs, nrhs, prhs)
integer plhs(*), prhs(*), nlhs, nrhs
In the gateway routine:
•Use the
mxCreate functions to create the
MATLAB arrays for your output
arguments. Set
plhs(1), (2), … to the
pointers to the newly created MATLAB
arrays.
•Use the
mxGet functions to extract your
data from
prhs(1), (2), …
•Call your Fortran subroutine passing
the input and output data pointers as
function parameters using
%val.
MATLAB
On return from
MEX-file
func:
[C,D]=func(A,B)
plhs(1)
is assigned
to
C and plhs(2) is
assigned to
D.