Thread Subject: Sample Matlab Engine Doesn't Work?

Subject: Sample Matlab Engine Doesn't Work?

From: David Doria

Date: 12 Mar, 2008 21:39:05

Message: 1 of 3

I tried this in c++, but it produces a blank plot! I linked
to libmx.lib libmex.lib libeng.lib.

Seems very odd, it is clearly almost working because it is
producing a plot, but there is nothing on it!!
Any thoughts?

int main()
{
Engine *ep;

if (!(ep = engOpen("\0"))) {
fprintf(stderr, "\nCan't start MATLAB engine\n");
Pause();
return EXIT_FAILURE;
}
engEvalString(ep, "x = 1:1:10);");
engEvalString(ep, "y = x.^2;");
engEvalString(ep, "plot(x,y);");
engEvalString(ep, "title('Test');");
Pause();

//Free memory, close MATLAB engine.
engEvalString(ep, "close;");

Subject: Sample Matlab Engine Doesn't Work?

From: James Tursa

Date: 13 Mar, 2008 06:37:18

Message: 2 of 3

On Wed, 12 Mar 2008 21:39:05 +0000 (UTC), "David Doria"
<daviddoria@gmail.com> wrote:

> engEvalString(ep, "x = 1:1:10);");

Typo, extra paren, this should be:

engEvalString(ep, "x = 1:1:10;");

The problem with using engEvalString is you don't get any feedback
that your string is invalid. There is a heavy burdon on the programmer
to examine the string carefully to make sure it is valid syntax, the
variables used are in existence, names are spelled correctly, etc.
etc. etc. It is good practice to copy & paste these strings into the
MATLAB workspace one by one to see that they do in fact work as
expected. This avoids wasting time trying to track down a non-existent
coding error in the C++ code itself.

James Tursa

Subject: Sample Matlab Engine Doesn't Work?

From: David Doria

Date: 13 Mar, 2008 11:59:01

Message: 3 of 3

Oh man! Really sorry for the dumb mistake. I guess it's good
to know that is the case for the future when my commands are
more than 10 characters hahaha.

Thanks for the help.

David

James Tursa <aclassyguywithaknotac@hotmail.com> wrote in
message <64iht3dv5ou8htupbb01sr7t3majehnhju@4ax.com>...
> On Wed, 12 Mar 2008 21:39:05 +0000 (UTC), "David Doria"
> <daviddoria@gmail.com> wrote:
>
> > engEvalString(ep, "x = 1:1:10);");
>
> Typo, extra paren, this should be:
>
> engEvalString(ep, "x = 1:1:10;");
>
> The problem with using engEvalString is you don't get any
feedback
> that your string is invalid. There is a heavy burdon on
the programmer
> to examine the string carefully to make sure it is valid
syntax, the
> variables used are in existence, names are spelled
correctly, etc.
> etc. etc. It is good practice to copy & paste these
strings into the
> MATLAB workspace one by one to see that they do in fact
work as
> expected. This avoids wasting time trying to track down a
non-existent
> coding error in the C++ code itself.
>
> James Tursa

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
engine Ned Gulley 12 Mar, 2008 23:15:09
rssFeed for this Thread
 

MATLAB Central Terms of Use

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 Terms prior to use.

Contact us at files@mathworks.com