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 13:51:02 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 47
Message-ID: <frdvs6$lim$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>
Reply-To: "David Doria" <daviddoria@gmail.com>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1205502662 22102 172.30.248.38 (14 Mar 2008 13:51:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 14 Mar 2008 13:51:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1105197
Xref: news.mathworks.com comp.soft-sys.matlab:457241



ok, I tried again to no avail...
I understand the stuff about the types and the pointer types
now, thanks for the explanation. I am clearly still missing
something else though.

In matlab, mexfunc(4) sets ans to 8.  class(ans) is double.

Here is the MEX code: (mexfunc.cpp)

#include "mex.h"

void timestwo(double y[], double x[])
{
  y[0] = 2*x[0];
}

void mexFunction( int nlhs, mxArray *plhs[],
                  int nrhs, const mxArray *prhs[] )
{
  double *x,*y;
  mwSize mrows,ncols;
  plhs[0] = mxCreateDoubleMatrix(1,1, mxREAL);
  x = mxGetPr(prhs[0]);
  y = mxGetPr(plhs[0]);
  timestwo(y,x);

}


And here is the c++ code:

engEvalString(ep, "cd 'C:\Documents and Settings\Dave\My
Documents\Visual Studio 2005\Projects\Matlab MEX';");

engEvalString(ep, "a=mexfunc(4);");
mxArray *test2 = NULL;
test2 = engGetVariable(ep, "a");
double *myout2;
myout2 = mxGetPr(test2); //Access violation on this line
double d;
d=*myout2;
cout << d << endl;

Any more clues for me? haha

Thanks,
Dave