Path: news.mathworks.com!not-for-mail
From: "David Doria" <daviddoria@gmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Call a MEX function from Matlab Engine?
Date: Fri, 14 Mar 2008 15:41:03 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 39
Message-ID: <fre6af$jpp$1@fred.mathworks.com>
References: <frc4bp$ipi$1@fred.mathworks.com> <frc7ir$s19$1@fred.mathworks.com> <frccfq$l2f$1@fred.mathworks.com> <frch5p$bdj$1@fred.mathworks.com> <frdvs6$lim$1@fred.mathworks.com> <fre31g$bk1$1@fred.mathworks.com>
Reply-To: "David Doria" <daviddoria@gmail.com>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1205509263 20281 172.30.248.35 (14 Mar 2008 15:41:03 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 14 Mar 2008 15:41:03 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1105197
Xref: news.mathworks.com comp.soft-sys.matlab:457260



As you guessed, test2 was 00000000.  For some reason my
compiler was completely skipping the line about "cd the
directory".  I removed the couple of lines before this code
that i plotted something just to test if the engine opened
properly and the compiler complained that I had used \
instead of / in the path... Why it ignored it with the plot
command I have NO idea.

But it worked for me now as well.  So now back to my first
question of how to call fminunc() from the engine.  I'm not
sure if this is exactly what you were suggesting, but I
think it will work:

1) I have test.cpp which contains f() which I intend to
minimize:
//for now I made it extra simple
double f()
{
	return 2.81;
}
2) I have mexfunc.cpp which contains mexFunction() which I
can now get the value from in main() in test.cpp
3) All thats left to do is call f() from mexFunction().  I
made a test.h and all I put in it is:
double f();

then in mexfunc.cpp I put:
#include "test.h"

Then I try to run 'mex mexfunc.cpp' in matlab and I get:

mexfunc.obj : error LNK2019: unresolved external symbol
"double __cdecl f(void)" (?f@@YANXZ) referenced in function
_mexFunction 

Any thoughts? I promise (well maybe not!) I'll leave you
alone after this :)

Dave