User`s manual
1 Calling C and Fortran Programs from MATLAB
1-4
You can call MEX-files exactly as you would call any M-function. For example,
a MEX-file called
conv2.mex on your disk in the MATLAB datafun toolbox
directory performs a 2-D convolution of matrices.
conv2.m only contains the
help text documentation. If you invoke the function
conv2 from inside
MATLAB, the interpreter looks through the list of directories on MATLAB’s
search path. It scans each directory looking for the first occurrence of a file
named
conv2 with the corresponding filename extension from the table or .m.
When it finds one, it loads the file and executes it. MEX-files take precedence
over M-files when like-named files exist in the same directory. However, help
text documentation is still read from the
.m file.
The Distinction Between mx and mex Prefixes
Routines in the API that are prefixed with mx allow you to create, access,
manipulate, and destroy
mxArrays. Routines prefixed with mex perform
operations back in the MATLAB environment.
mx Routines
The array access and creation library provides a set of array access and
creation routines for manipulating MATLAB arrays. These subroutines, which
are fully documented in the online API reference pages, always start with the
prefix
mx. For example, mxGetPi retrieves the pointer to the imaginary data
inside the array.
Although most of the routines in the array access and creation library let you
manipulate the MATLAB array, there are two exceptions — the IEEE routines
and memory management routines. For example,
mxGetNaN returns a double,
not an
mxArray.
mex Routines
Routines that begin with the mex prefix perform operations back in the
MATLAB environment. For example, the
mexEvalString routine evaluates a
string in the MATLAB workspace.
Solaris
mexsol
Windows
dll
Table 1-1: MEX-File Extensions (Continued)
Platform MEX-File Extension