Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: mexCallMATLAB populating inputs
Date: Thu, 20 Aug 2009 09:34:04 +0000 (UTC)
Organization: Indian Institute of Technology
Lines: 36
Message-ID: <h6j5ac$dg8$1@fred.mathworks.com>
References: <70c8e2ce-c34a-454e-8c40-d186e7aa61b4@s6g2000vbp.googlegroups.com> <add8f90f-3a82-4810-9437-666b0eb17d0b@z28g2000vbl.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 1250760844 13832 172.30.248.38 (20 Aug 2009 09:34:04 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 20 Aug 2009 09:34:04 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 223861
Xref: news.mathworks.com comp.soft-sys.matlab:564700


Dear James,
I tried your recommendation and I am getting this strange result. Why?

with regards,
ramana
**************************
#include "mex.h"
void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) {
    double a[] = {1, 2, 3, 4};
    double *pr;
    mxArray *prhs1,*output[1];
    int i;
    prhs1 = mxCreateDoubleMatrix(4, 1, mxREAL);
    pr = mxGetPr(prhs1);
    for( i=0; i<3; i++ ) {
        pr[i] = a[i];
    }
    mexCallMATLAB(1, output, 1, &prhs1, "mymfile");    
    plhs[0] = output[0];
}
****************************
function [output]=mymfile(input)
output = input(1)+2*input(2)-input(3)^3 + input(4);
*****************************
>> mex demo2.c
>> b=demo2()

b =

   -22

>> mymfile([1 2 3 4])

ans =

   -18