Path: news.mathworks.com!not-for-mail
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$1@newscl01ah.mathworks.com>
References: <l0s63d$f2e$1@newscl01ah.mathworks.com> <l0s6ei$krk$1@newscl01ah.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: rubyext-03-ls.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: newscl01ah.mathworks.com 1378988406 22752 172.20.102.179 (12 Sep 2013 12:20:06 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 12 Sep 2013 12:20:06 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 4323779
Xref: news.mathworks.com comp.soft-sys.matlab:802286

"Hariprasad" wrote in message <l0s6ei$krk$1@newscl01ah.mathworks.com>...
> "Hariprasad" wrote in message <l0s63d$f2e$1@newscl01ah.mathworks.com>...
> > 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;

mxCallMATLAB(1,lhs,2,rhs,"rand");

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