Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Pass by reference in MexFunction
Date: Wed, 17 Apr 2013 18:40:08 +0000 (UTC)
Organization: HCL TECHNOLOGIES LIMITED
Lines: 19
Message-ID: <kkmqa8$kv8$1@newscl01ah.mathworks.com>
References: <ibmvr7$9no$1@fred.mathworks.com> <ibnee3$mer$1@fred.mathworks.com> <ibni0g$cud$1@fred.mathworks.com> <ibo39m$pgo$1@fred.mathworks.com> <iv9uu7$rqk$1@newscl01ah.mathworks.com> <ivah59$au6$1@newscl01ah.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: www-03-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: newscl01ah.mathworks.com 1366224008 21480 172.30.248.48 (17 Apr 2013 18:40:08 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 17 Apr 2013 18:40:08 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 4103771
Xref: news.mathworks.com comp.soft-sys.matlab:793759


> void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
> {
>     double *pr;
>     pr = mxGetPr(prhs[0]);
>     pr[0] = 99.0;
> }

Hi James Tursa

Even I'm in a similar situation as described by Marc. I tested the solution provided by you and it works. But the Matlab documentation says that prhs values should not be modified in MEX functions.

"Array of pointers to the input mxArrays. Do not modify any prhs values in your MEX-file. Changing the data in these read-only mxArrays can produce undesired side effects."

Reference - http://www.mathworks.com/help/matlab/apiref/mexfunction.html

So I'm not sure if I should go ahead and use the solution as it works for me. Please advise.

Satheesh