From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: rand() using mexCallMATLAB
Date: Thu, 12 Sep 2013 12:20:06 +0000 (UTC)
Organization: UniVistaar Solutions LLC
Lines: 21
Message-ID: <l0sbhm$m70$>
References: <l0s63d$f2e$> <l0s6ei$krk$>
Reply-To: <HIDDEN>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: 1378988406 22752 (12 Sep 2013 12:20:06 GMT)
NNTP-Posting-Date: Thu, 12 Sep 2013 12:20:06 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 4323779
Xref: comp.soft-sys.matlab:802286

"Hariprasad" wrote in message <l0s6ei$krk$>...
> "Hariprasad" wrote in message <l0s63d$f2e$>...
> > I want to use the existing Matlab rand() function in a Mex function. I have two int variables(rows and cols) which determine the size of the array of random numbers. Since I have to use mexCallMATLAB for using the Matlab rand() function, I don't know how to pass the 2 int variables as the prhs[] input to mexCallMATLAB. Any help will be really helpful.

i have done something like this inside the mexFunction()

mxArray *lhs,*rhs[2];
int *p1,*p2;
double *randoms;

lhs = mxCreateDoubleMatrix(m,no_of_levels,mxREAL);  /* m =2, no_of_levels = 4 */
randoms = mxGetPr(lhs);
rhs[0] = mxCreateNumericMatrix(1,1,mxUINT8_CLASS,mxREAL);
rhs[1] = mxCreateNumericMatrix(1,1,mxUINT8_CLASS,mxREAL);
p1 = mxGetPr(rhs[0]); *p1 = m;
p2 = mxGetPr(rhs[1]); *p2 = no_of_levels;


but the data is zero in randoms. Where am I going wrong??