For example, this routine multiplies an input scalar times an input scalar or matrix. This is the Fortran code for the computational subroutine. Below is the gateway routine that calls xtimesy , the computation subroutine that multiplies a scalar by a scalar or matrix. C Check for proper number of arguments. C Load the data into Fortran arrays.
C Call the computational subroutine.
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 .