Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: rand() using mexCallMATLAB
Date: Fri, 13 Sep 2013 05:06:09 +0000 (UTC)
Organization: UniVistaar Solutions LLC
Lines: 36
Message-ID: <l0u6g1$d3n$1@newscl01ah.mathworks.com>
References: <l0s63d$f2e$1@newscl01ah.mathworks.com> <l0s6ei$krk$1@newscl01ah.mathworks.com> <l0sbhm$m70$1@newscl01ah.mathworks.com> <l0sjvm$50f$1@newscl01ah.mathworks.com> <l0slcm$ki8$1@newscl01ah.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: rubyext-01-ls.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: newscl01ah.mathworks.com 1379048769 13431 172.20.102.177 (13 Sep 2013 05:06:09 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 13 Sep 2013 05:06:09 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 4323779
Xref: news.mathworks.com comp.soft-sys.matlab:802339

"James Tursa" wrote in message <l0slcm$ki8$1@newscl01ah.mathworks.com>...
> "James Tursa" wrote in message <l0sjvm$50f$1@newscl01ah.mathworks.com>...
> 
> >  mxArray *lhs,*rhs[2];
> 
> Typo, make the above line:
> 
>   mxArray *lhs[1],*rhs[2];
> 
> James Tursa

Hello Sir, I made the changes as directed by you but still the 'randoms' is Zero. I have used the codes as follows: -

double *randoms1, *randoms2;    /* need 2 diff sized arrays 2x4  and 2x1  */
mxArray *rhs1[2], *rhs2[2], *lhs1[1], *lhs2[1];

/* (m=2,no_of_levels=4) from int to double would be a problem?*/ 
lhs1[0] = mxCreateDoubleMatrix(m,no_of_levels,mxREAL); 
lhs2[0] = mxCreateDoubleMatrix(1,m,mxREAL);

rhs1[0] = mxCreateDoubleScalar(m);
rhs1[1] = mxCreateDoubleScalar(no_of_levels);

rhs2[0] = mxCreateDoubleScalar(m);    
rhs2[1] = mxCreateDoubleScalar(1);

mexCallMATLAB(1,lhs1[0],2,rhs1,"rand"); 
mxDestroyArray(rhs1[0]);mxDestroyArray(rhs1[1]);
randoms1 = mxGetPr(lhs1[0]);

like wise I call mexCallMATLAB(1,lhs2[0],2,rhs2,"rand");

I also use  mexEvalString("rand('twister',sum(100*clock));"); 
to set the seed before the start of each iteration. Would this be the cause of trouble? Also the randoms1 and randoms2 will be regenerated many times in the code(at least 100 times), so I guess I should use mxDestroyArray at the end of the codes, right?

Hariprasad