User`s manual

3 Creating Fortran MEX-Files
3-22
As this example shows, creating MEX-file gateways that handle multiple
inputs and outputs is straightforward. All you need to do is keep track of which
indices of the vectors
prhs and plhs correspond to which input and output
arguments of your function. In this example, the input variable
x corresponds
to
prhs(1) and the input variable y to prhs(2).
For an input scalar
x and a real 3-by-3 matrix,
x = 3; y = ones(3);
typing
z = xtimesy(x, y)
yields this result
z =
3 3 3
3 3 3
3 3 3
Handling Complex Data
MATLAB stores complex double-precision data as two vectors of numbers —
one contains the real data and one contains the imaginary data. The API
provides two functions,
mxCopyPtrToComplex16 and mxCopyComplex16ToPtr,
which allow you to copy the MATLAB data to a native
complex*16 Fortran
array.
This example takes two complex vectors (of length 3) and convolves them.
C $Revision: 1.14 $
C==============================================================
C
C convec.f
C Example for illustrating how to pass complex data from
C MATLAB to FORTRAN (using COMPLEX data type) and back
C again.
C
C Convolves two complex input vectors.
C
C This is a MEX-file for MATLAB.
C Copyright (c) 1984-2000 The MathWorks, Inc.