Vous êtes sur la page 1sur 5

Without Remorse

Random House
Audio...
New $26.95
Best $26.95
Privacy Information
Home
Video tutorials
Record the linux
desktop
(screencast)
Another one about
linux desktop
screencast.
Introduction to Gimp
Introduction to R
Introduction to
OpenOice
Linux tips
A detail explanation
about Linux
Desktop
broadcasting
Cong VNC on debian
linux system.
The table of
equivalents/replace
ments of Windows
software in Linux
Enable and disable
Ubuntu root
Web linux4research.blogspot.com
1 0 / 2 1 / 0 7
Calling Matlab functions
from C++
It is very useful to call matlab functions
from C++. For example, I can use C++
to do most of the calculations, and just
use matlab functions to plot the results,
or I can use Matlab to do some matrix
manipulations. Here I illustrate how to
do that under linux.
1. Matlab7.4.0 (2007a) must be installed.
2. MUST have gcc-4.1.1 compiler. It
seems that gcc-4.1.2 doesn't work. Check
here for the supported compilers. If your
system doesn't have the right compiler,
install one rst. See the following tips for
installing the compiler.
3. Check whether your system has csh or
not. If you don't have it, install it.
DESCRI PT I ON OF
T HI S BL OG.
I am a researcher
working in the
biological physics eld. I
started to use Linux
back in 2001. After that,
I fall in love with Linux.
I use it in my research
and also daily work,
such as document
processing, web surng
etc. In this blog I record
my Linux experience. I'd
like to focus on the
research experience
using Linux, especially I
want to explain or give
some simple tutorials on
software commonly
used in research, such
as OpenOice, Octave,
R, xg, gimp, C++ , etc.
This blog was rst set
up mainly for my
personal use, but it turn
out to be more useful
than I had thought.
Please note that I have
no intention to claim
that the materials here
are my original. Actually
most of them just my
collection from all over
the world when I
0 mais Prximo blog Criar um blog Login
LI NUX F OR RES EARCH
Novidades NET Empresas
netcombo.com.br/Empresas
Empresa que Economiza vai Longe. Planos a partir de R$ 29,80. Vem!
Linux for research: Calling Matlab functions fro... http://linux4research.blogspot.com.br/2007/10/cal...
1 de 5 05-09-2014 20:12
password
fstab le user
permission
conguration
Change apt-get
default archives
directory
Stop Xserver to install
Nvidia driver
ldcong/set up
LD_LIBRARY_PATH
Convert eps le to g
le so that Xg can
read
My favorite linux
programs
Using rsync to backup
data
Best linux graphics
program
Scientic programs
C++ programming
C++ Quick
Reference
Calling Matlab
functions from
C++ program
C++ naming
standards
Using C++ to
read a tab
separated
Matlab matrix
Function objects
in C++
(functors)
g++ and numerical
recipes
Classes with
circular
dependence
Virtual function and
4. In your .bashrc le, dene the
LD_LIBRARY_PATH
LD_LIBRARY_PATH=/home/xxx/program
/matlab74/bin/glnx86:/home/
xxx/program/matlab74/sys/os/glnx86
/:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH
Also make sure that Matlab is in your
path.
export PATH=/home/xxx/program
/matlab74/bin/:$PATH
Note: Matlab is installed in /home/xxx
/program/matlab74/ directory. You need
to change according to your system.
5. Following the procedures in the
matlab document. Compiling and Linking
MATLAB Engine Programs . If everything
works ne, this should give executable
le "engdemo". Inside matlab if you want
to run this you should use !./engdemo
instead of the !engdemo.
6. Now you can also use the following to
compile the "engdemo.c" in the linux
console instead of inside matlab.
g++ -o engdemo engdemo.c -I
/home/xxx/program/matlab74/extern
/include/ -L
/home/xxx/program/matlab74/bin/glnx86/
-leng -lm
Pay attention to the include path, and the
lib path. Also there is the ag -leng.
Now you should be able to use the
Matlab engine to call Matlab functions
from c++. If you have some errors such
as "matlab engine can not start" the
chance is your compiler version is not
the same one as matlab is built. You
searched the internet to
nd solutions. If there
is any, if you think
infringement of your
copyright, please
contact me and I will
immediately take
actions on that.
BL OG ARCHI VE
2014 (2)
2013 (2)
2012 (3)
2011 (9)
2010 (23)
2009 (19)
2008 (17)
2007 (57)
October (9)
Calling Matlab
functions from
C++
Tutorial on
MATLAB
executables
(MEX les)
How to Compile
MATLAB C++
Math Library
Ubuntu install
matlab 2007.
Introduction to
programming
with OpenCV
Compile Qt with
OpenGL support.
python problem.
Linux for research: Calling Matlab functions fro... http://linux4research.blogspot.com.br/2007/10/cal...
2 de 5 05-09-2014 20:12
pure virtual
function
Qt Programming
Octave
Introduction to
Octave
R
A nice tutorial
OpenOice
L ABEL S
linux tips (49)
Programming related
(41)
Mac (18)
Chinese input related
(6)
vedio (4)
tricks (1)
vi (1)
should use the exact same compiler as
Matlab requests.
Here are some hints about setting up the
right compiler.
Compiling and linking made diicult
Let's suppose we wanted to create an
eicient MATLAB routine that calculates
the height of the Normal probability
density function (pdf) at a given point on
the line. That there are at least ve
gazillion MATLAB implementations that
already calculate this quantity is beside
the point. (Normally, when you decide to
write a MATLAB routine in C++, you
should make sure it is worth your while!)
Before we embark on the actual C++
coding, we need to examine how
MATLAB creates a MEX File. The exact
procedure is system-dependent, so what
I describe here may dier slightly from
your setup. At school I have access to a
machine installed with the Linux
operating system, and I have my own
Apple computer with Mac OS X. Both
these operating systems are Unix-like,
hence their dierences will be rather
cosmetic.
In order to build MEX les, we need to
make sure that we have the proper
compiler installed on our system. On my
Linux machine, I'm using MATLAB 7.3
(R2006b), and according to MathWorks
product support it was built with the
GNU Compiler Collection (GCC) 3.4.5.
Unfortunately, I did not have this
particular version of the compiler
installed on my system. Dierent
versions of the same compiler are
eectively dierent compilers, as they
follow dierent conventions. You should
LIBS
Enable and Disable
Ubuntu Root
Password --
Debian ...
September (1)
August (6)
July (1)
June (1)
May (12)
April (11)
March (3)
February (10)
January (3)
2006 (52)
Mens Slim Casual
Items
amazon.com/thelees
All mens slim and luxury
Clothings Free Shipping over
$100
Linux for research: Calling Matlab functions fro... http://linux4research.blogspot.com.br/2007/10/cal...
3 de 5 05-09-2014 20:12
Newer Post Older Post
never link libraries or object code unless
they are compiled in the same way. I
downloaded the GCC source from my
local university FTP mirror and built the
entire package on my system. GCC
includes compilers for many dierent
languages, and they can be found in the
bin subdirectory of the GCC software
installation. MATLAB uses three of them:
the C compiler gcc, the C++ compiler g++,
and the Fortran 77 compiler g77. When
installing GCC, it is a bad idea to blindly
follow the default installation as it may
overwrite the existing compilers. You
should install it in a new directory.
Afterward, to make things simpler, I
created a symbolic link to each of the
compilers like so:
cd /usr/bin
ln -s gcc-install-path/bin/gcc gcc-3.4.5
Then I did the same thing for the other
two compilers. Since /usr/bin is in the
path (see the environment variable PATH),
I can call the program anywhere I am
simply by typing gcc-3.4.5. By including
the version number in the symbolic link,
I avoid calling version 3.4.5 of gcc unless
I really want to.
LABELS: PROGRAMMI NG RELATED
NO COMMENTS:
Post a Comment
LI NKS TO THI S POST
Create a Link
Home
Subscribe to: Post Comments (Atom)
Celular
Promoo
48% Off
celular.cissamagazi
O Celular que Voc
Queria Est Aqui
Preos Imperdiveis
Pague Em At 12x
...
Linux for research: Calling Matlab functions fro... http://linux4research.blogspot.com.br/2007/10/cal...
4 de 5 05-09-2014 20:12
15-120W LED High Bay Bulb
eneltec-led.com
LED High Bay Bulbs replacement for MH/HPS
Bulbs,with high quality.
Linux for research: Calling Matlab functions fro... http://linux4research.blogspot.com.br/2007/10/cal...
5 de 5 05-09-2014 20:12

Vous aimerez peut-être aussi