User`s guide

Microsoft Windows on PCs
2-23
copy of the options file in your user profile directory to correspond to your
specific needs and sa ve the mo difie d file. After completing this proce ss, the
mex
script wil l use t he ne w opt ions file everytime with your m od ified s ett ings.
Temporarily Changing the Compiler. Totemporarilychange your CorC++compiler,
use t he
-f option, as in
mex -f <file> …
The-f option tells the mex script to usetheoptionsf ile, <file>.If<file> is not
in the current directory, then
<file> must be the full pa thname to the desired
options file. Using the
-f option tells the mex script to use the specified options
file for the current execution of
mex only; it does not reset the default compiler.
Creating MEX-Files
The <matlab>\extern\examples\mex directory contains C source code for the
example
yprime.c. To verify that your system can create MEX-files, enter at
the MATLAB prompt
cd([matlabroot '\extern\examples\mex'])
mex yprime.c
This should create the yprime.dll MEX-file. MEX-files created on Windows
95/98/2000 or NT always have the extension
dll.
You can now call
yprime as if it were an M-function. For example,
yprime(1,1:4)
ans =
2.0000 8.9685 4.0000 -1.0947
If you encounter problems generating the MEX-file or g etting the correct
results, refer to “External Interfaces/API” for additi onal information ab out
MEX-files.
Using an IDE
TheM athWorksprovidesaMATLABadd-infor theV isualStudiodevelopment
system that lets you work easily within Microsoft Visual C/C++ (MSVC)
environment to create and debug MEX-files. The MATLAB add-in for Vi sual
Studio is includ ed w it h MAT LAB and is auto mat ical ly i nsta lle d when you run
mex -setup and select Microsoft Visual C/C++ version 5 or 6. For more