|
|
|||
![]() |
Department of Engineering |
| University of Cambridge > Engineering Department > computing help > programs > matlab |
mex is a program used when compiling C, C++ or Fortran code to work with Matlab. You can run it from within matlab or from the compile line. Depending on the way you run it and the language you use, you may need to configure it for use on our central system.
cd /tmp
demofile = [matlabroot '/extern/examples/eng_mat/engdemo.c'];
copyfile(demofile, '.');
optsfile = [matlabroot '/bin/engopts.sh'];
mex('-f', optsfile, 'engdemo.c');
!./engdemo
You might get a warning
Warning: You are using gcc version "4.3.1". The earliest gcc version supported
with mex is "4.1". The latest version tested for use with mex is "4.2".
To download a different version of gcc, visit http://gcc.gnu.org
but the final line should work. On our system you should see a matlab window appearing when you run engdemo.
If then you open a terminal window and do the following from the unix command line
cd /tmp mex -f /usr/local/apps/matlab/matlab2009b/bin/engopts.sh engdemo.c
you should also be able to produce an engdemo program but when you try to run engdemo you're likely to get an error message like the following
./engdemo: error while loading shared libraries: libeng.so: cannot open shared object file: No such file or directory
You need to type the following first
export LD_LIBRARY_PATH=/usr/local/apps/matlab/matlab2009b/bin/glnxa64:/usr/local/apps/matlab/matlab2009b/sys/os/glnxa64:$LD_LIBRARY_PATH
The /usr/local/apps/matlab/matlab2009b/ part of this command might change in the future. To find its current value, type matlabroot inside matlab.
cp /usr/local/apps/matlab/matlab2009b/bin/engopts.sh ~
Edit the copy you've made (~/engopts.sh) changing g95 to gfortran. You'll then need to tell mex to use this file. The folowing lines, run inside matlab, copy a fortran demo file and try to compile then run it. You'll need to replace your_home_folder with the name of your home folder (type echo $HOME in Unix to get it).
cd /tmp
demofile = [matlabroot '/extern/examples/eng_mat/fengdemo.F'];
copyfile(demofile, '.');
optsfile = 'your_home_folder/engopts.sh';
mex('-f', optsfile, 'fengdemo.F');
!./fengdemo
This should work on CUED's central system.
cd /tmp mex -f ~/engopts.sh fengdemo.Fbut again you won't be able to run the resulting program until you've set LD_LIBRARY_PATH as above.
| | computing help | Matlab | |