Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: mexCallMATLAB populating inputs
Date: Thu, 20 Aug 2009 00:39:19 +0000 (UTC)
Organization: Boeing
Lines: 19
Message-ID: <h6i5vn$kj9$1@fred.mathworks.com>
References: <70c8e2ce-c34a-454e-8c40-d186e7aa61b4@s6g2000vbp.googlegroups.com> <494fa8a2-72c1-4c6a-a599-69269928edd2@r27g2000vbn.googlegroups.com>
Reply-To: <HIDDEN>
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 1250728759 21097 172.30.248.38 (20 Aug 2009 00:39:19 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 20 Aug 2009 00:39:19 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 756104
Xref: news.mathworks.com comp.soft-sys.matlab:564615


John Harrold <john.m.harrold@gmail.com> wrote in message <494fa8a2-72c1-4c6a-a599-69269928edd2@r27g2000vbn.googlegroups.com>...
> 
> What syntax in C would allow me to populate the prhs1 array such that
> I could subsequently call the mexCallMATLAB function?

  double a[] = {1, 2, 3, 4};
  double *pr;
  mxArray *plhs1[1], *prhs1;
  int i;
  prhs1 = mxCreateDoubleMatrix(4, 1, mxREAL);
  pr = mxGetPr(prhs1);
  for( i=0; i<3; i++ ) {
      pr[i] = a[i];
  }
  mexCallMATLAB(1, plhs1, 1, &prhs1, "mymfile");

For readability, you might consider making plhs1 and prhs1 either both arrays or both pointers. That way using them for arguments in mexCallMATLAB would look the same instead of different as I have them above.

James Tursa