The help on calling Matlab from c++ mentions this demo file
in the maltabroot/extern/examples/eng_mat, but my
installation doesn't seen to have it. Anyone know where I
can get a copy? Thanks,
"Naor Movshovitz" <lazy_n@yahoo.com> wrote in message
<fqrp3f$kq2$1@fred.mathworks.com>...
> The help on calling Matlab from c++ mentions this demo file
> in the maltabroot/extern/examples/eng_mat, but my
> installation doesn't seen to have it. Anyone know where I
> can get a copy? Thanks,
>
> -n
I don't feel comfortable posting code from a MATLAB
installation, but you can probably find engine examples in
the FEX if you are just looking for sample code. For example
I have an engine example in submission 17660. Or if you have
questions about doing something specific I can probably
create an example for you.
On Mar 9, 12:07=A0am, "James Tursa" <aclassyguywithakno...@hotmail.com>
wrote:
> "Naor Movshovitz" <laz...@yahoo.com> wrote in message
>
> <fqrp3f$kq...@fred.mathworks.com>...
>
> > The help on calling Matlab from c++ mentions this demo file
> > in the maltabroot/extern/examples/eng_mat, but my
> > installation doesn't seen to have it. Anyone know where I
> > can get a copy? Thanks,
>
> > -n
>
> I don't feel comfortable posting code from a MATLAB
> installation, but you can probably find engine examples in
> the FEX if you are just looking for sample code. For example
> I have an engine example in submission 17660. Or if you have
> questions about doing something specific I can probably
> create an example for you.
>
> James Tursa
Thanks James,
Actually, I was just curious about what was in this example, and why
is it missing from my installation. I may have specific questions
about calling matlab from c++ later, if so I will start a new thread.
-naor
lazy_n <lazy_n@yahoo.com> wrote in message > Actually, I was
just curious about what was in this example, and why
> is it missing from my installation.
FYI, engdemo.c is a simple program that uses the following
functions:
- Opens the engine
- Creates local 1-dim mxArray and puts it into the engine
workspace
- Creates a plot using this variable
- Reads a string from the console and evaluates it in the
engine workspace
- Gets the result from the engine workspace to a local
mxArray variable
- Closes the engine
I am having a similar problem... I can compile and run
engdemo.c (and a few simple .c files of my own) with no
problems, but I cannot get a .cpp file to be compiled.
I tried writing very simple c++ engine files, but all I get
from matlab is an error stating "not a normal file"
I searched for the engdemo.cpp file to see what is missing
in my tests but it is not where the documentation say it
should be.
Anyone knows where it is? or (even better) knows how to
compile engine programs written in c++ using matlab or an
external IDE (eclipse in my case)?
"Yair Movshovitz" <yairmov@gmail.com.remove.this> wrote in
message <fr2s95$8n7$1@fred.mathworks.com>...
> "James Tursa" <aclassyguywithaknotac@hotmail.com> wrote in
> message <fr1f52$ba6$1@fred.mathworks.com>...
> > P.S. You can find another engine example here:
> >
> >
> http://www.mathworks.com/matlabcentral/newsreader/view_thread/165277
> >
> > James Tursa
> >
>
>
> I am having a similar problem... I can compile and run
> engdemo.c (and a few simple .c files of my own) with no
> problems, but I cannot get a .cpp file to be compiled.
> I tried writing very simple c++ engine files, but all I get
> from matlab is an error stating "not a normal file"
> I searched for the engdemo.cpp file to see what is missing
> in my tests but it is not where the documentation say it
> should be.
>
> Anyone knows where it is? or (even better) knows how to
> compile engine programs written in c++ using matlab or an
> external IDE (eclipse in my case)?
>
> Thanks,
> Yair
I have had no problems compiling C++ files with MATLAB using
VC++ 8.0. Could you post an example file for me to look at?
Which C++ compiler are you using?
"James Tursa" <aclassyguywithaknotac@hotmail.com> wrote in
message <fr3ls6$k8a$1@fred.mathworks.com>...
> "Yair Movshovitz" <yairmov@gmail.com.remove.this> wrote in
> message <fr2s95$8n7$1@fred.mathworks.com>...
> > "James Tursa" <aclassyguywithaknotac@hotmail.com> wrote in
> > message <fr1f52$ba6$1@fred.mathworks.com>...
> > > P.S. You can find another engine example here:
> > >
> > >
> >
> http://www.mathworks.com/matlabcentral/newsreader/view_thread/165277
> > >
> > > James Tursa
> > >
> >
> >
> > I am having a similar problem... I can compile and run
> > engdemo.c (and a few simple .c files of my own) with no
> > problems, but I cannot get a .cpp file to be compiled.
> > I tried writing very simple c++ engine files, but all I get
> > from matlab is an error stating "not a normal file"
> > I searched for the engdemo.cpp file to see what is missing
> > in my tests but it is not where the documentation say it
> > should be.
> >
> > Anyone knows where it is? or (even better) knows how to
> > compile engine programs written in c++ using matlab or an
> > external IDE (eclipse in my case)?
> >
> > Thanks,
> > Yair
>
> I have had no problems compiling C++ files with MATLAB using
> VC++ 8.0. Could you post an example file for me to look at?
> Which C++ compiler are you using?
>
> James Tursa
>
Hi James,
Thanks for trying to help.
Here is a simple function:
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "/usr/local/matlab75/extern/include/engine.h"
// also tried it with only #include "engine.h"
#define BUFSIZE 256
#include <iostream>
using namespace std;
int main(){
Engine *ep;
/*
* Start the MATLAB engine locally by executing the string
* "matlab"
*/
if (!(ep = engOpen("\0"))) {
fprintf(stderr, "\nCan't start MATLAB engine\n");
return EXIT_FAILURE;
}
cout << "using a cpp command" << endl;
/* evaluate an m file */
engEvalString(ep, "plot(1:4, 1:4)");
/*
* use fgetc() to make sure that we pause long enough to be
* able to see the plot
*/
printf("Hit return to continue\n\n");
fgetc(stdin);
/* Close the matlab Engine */
engClose(ep);
return EXIT_SUCCESS;
}
I am running a linux machine (ubuntu 7.1).
I am compiling using gcc and getting the error:
mex: callingMatlabTest.cpp not a normal file or does not exist.
"Yair Movshovitz" <yairmov@gmail.com.remove.this> wrote in
message <fr3qpm$lqt$1@fred.mathworks.com>...
>
> I am running a linux machine (ubuntu 7.1).
> I am compiling using gcc and getting the error:
> mex: callingMatlabTest.cpp not a normal file or does
not exist.
>
>
> Thanks,
> Yair
Your example code compiles and runs fine, without any
modifications, using VC++ 8.0. What mex compile commands
are you using to build the exe?
"James Tursa" <aclassyguywithaknotac@hotmail.com> wrote in
message <fr3v6a$ii2$1@fred.mathworks.com>...
> > ... without any modifications...
>
> Not quite true. I did use
>
> #define "engine.h"
>
> instead of your longer define for this.
>
> James Tursa
>
>
Hi James,
Sorry for the long silence, I wasn't near my computer much
this last week.
I am now able to compile and run this simple function,
but when trying to run a more complicated project I get the
(run-time) error :
undefined symbol mxCreateDoubleMatrix
"Yair Movshovitz" <yairmov@gmail.com.remove.this> wrote in
message <frl9r6$7h1$1@fred.mathworks.com>...
> I am now able to compile and run this simple function,
> but when trying to run a more complicated project I get the
> (run-time) error :
> undefined symbol mxCreateDoubleMatrix
>
> Thanks,
> Yair
Do you have multiple files? mxCreateDoubleMatrix is defined
in the engine.h file.
"James Tursa" <aclassyguywithaknotac@hotmail.com> wrote in
message <fropd2$dst$1@fred.mathworks.com>...
> "Yair Movshovitz" <yairmov@gmail.com.remove.this> wrote in
> message <frl9r6$7h1$1@fred.mathworks.com>...
>
> > I am now able to compile and run this simple function,
> > but when trying to run a more complicated project I get
the
> > (run-time) error :
> > undefined symbol mxCreateDoubleMatrix
> >
> > Thanks,
> > Yair
>
> Do you have multiple files? mxCreateDoubleMatrix is
defined
> in the engine.h file.
>
> James Tursa
>
>
I have 1 cpp file and it's relevant .h file.
My problem is as follows:
I need the matlab engine complier to produce a shared
library. I was unable to find a compiler flag that tells
the mex function not to produce an executable so I am
compiling with another IDE (Eclipse). The compilation
process finishes without any errors/warnings.
On run-time I get the undefined symbol mxCreateDoubleMatrix
error. I read somewhere in the Mathworks help that I need
to export a number of symbols (mexFunction etc')
but I am not sure where such a thing should be done.
Public Submission Policy
NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for
all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content.
Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available
via MATLAB Central. Read the complete Disclaimer prior to use.