Path: news.mathworks.com!newsfeed-00.mathworks.com!newsfeed2.dallas1.level3.net!news.level3.com!postnews.google.com!s6g2000vbp.googlegroups.com!not-for-mail
From: John Harrold <john.m.harrold@gmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: mexCallMATLAB populating inputs
Date: Wed, 19 Aug 2009 13:27:00 -0700 (PDT)
Organization: http://groups.google.com
Lines: 46
Message-ID: <70c8e2ce-c34a-454e-8c40-d186e7aa61b4@s6g2000vbp.googlegroups.com>
NNTP-Posting-Host: 67.20.193.200
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
X-Trace: posting.google.com 1250713621 26025 127.0.0.1 (19 Aug 2009 20:27:01 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Wed, 19 Aug 2009 20:27:01 +0000 (UTC)
Complaints-To: groups-abuse@google.com
Injection-Info: s6g2000vbp.googlegroups.com; posting-host=67.20.193.200; 
	posting-account=22diBQoAAAAD5i1tJbtrsS2fX2hlob6K
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; 
	rv:1.9.1.2) Gecko/20090729 Firefox/3.0.5, Ant.com Toolbar 
	1.2,gzip(gfe),gzip(gfe)
Xref: news.mathworks.com comp.soft-sys.matlab:564559


Howdy folks,

I had a class in C sometime in the previous century, but truth be told
I never really understood pointers. I've recently come to a point
where I need to call matlab m-files from some ode simulations I'm
running, and I've been trying to incorporate the mexCallMATLAB
function into these simulations. I've tried to create a simple example
to figure this out. As an example I'd like to call the following m-
file from within a mex function:

<mymfile.m>
function [output]=mymfile(input)

output = input(1)+2*input(2)-input(3)^3 + input(4);
</mymfile.m>

So if I call this from within matlab I get the following:

>> mymfile([1 2 3 4])

ans =

   -18

Now I've constructed the following mex file

<mexfile.c>
#include "mex.h"
void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray
*prhs[] )
{
  int nlhs1, nrhs1;
  mxArray *plhs1[1], *prhs1;
  prhs1 =  mxCreateDoubleMatrix(4, 1, mxREAL);


  /* how do I populate prhs1? */

  nlhs1 = 1;  nrhs1 = 1;
  mexCallMATLAB(nlhs1,plhs1,nrhs1,prhs1,"mymfile");
}
</mexfile.c>

As the comment above indicates. I want to know how to go about
populating the prhs1 with my input (in this case 1 2 3 4).  I
apologize for the simple question here, I'm just at a loss with this.