In this figure a call to the MEX-file named func of the form [C, D] = func(A,B) tells MATLAB to pass variables A and B to your MEX-file. C and D are left unassigned.

The func.c gateway routine uses the mxCreate function to create the MATLAB arrays for your output arguments. It sets plhs[0], [1], ... to the pointers to the newly created MATLAB arrays. It uses the mxGet functions to extract your data from prhs[0], [1], ... Finally, it calls your C subroutine, passing the input and output data pointers as function parameters.

On return to MATLAB, plhs[0] is assigned to C and plhs[1] is assigned to D.