User`s manual

Examples of Fortran MEX-Files
3-19
C Load the data into y_pr, which is the output to MATLAB.
call mxCopyReal8ToPtr(y, y_pr, size)
return
end
After performing error checking to ensure that the correct number of inputs
and outputs was assigned to the gateway subroutine and to verify the input
was in fact a numeric matrix,
matsq.f creates a matrix for the argument
returned from the computational subroutine. The input matrix data is then
copied to a Fortran matrix by using
mxCopyPtrToReal8. Now the computational
subroutine can be called, and the return argument can then be placed into
y_pr, the pointer to the output, using mxCopyReal8ToPtr.
For a 2-by-3 real matrix
x = [1 2 3; 4 5 6];
typing
y = matsq(x)
produces this result
y =
149
16 25 36
Passing Two or More Inputs or Outputs
The plhs and prhs parameters are vectors that contain pointers to each
left-hand side (output) variable and right-hand side (input) variable.
Accordingly,
plhs(1) contains a pointer to the first left-hand side argument,
plhs(2) contains a pointer to the second left-hand side argument, and so on.
Likewise,
prhs(1) contains a pointer to the first right-hand side argument,
prhs(2) points to the second, and so on.
For example, this routine multiplies an input scalar times an input scalar or
matrix. This is the Fortran code for the computational subroutine.
subroutine xtimesy(x, y, z, m, n)
real*8 x, y(3,3), z(3,3)
integer m, n