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$>
References: <l0s63d$f2e$> <l0s6ei$krk$> <l0sbhm$m70$> <l0sjvm$50f$> <l0slcm$ki8$>
Reply-To: <HIDDEN>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: 1379048769 13431 (13 Sep 2013 05:06:09 GMT)
NNTP-Posting-Date: Fri, 13 Sep 2013 05:06:09 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 4323779
Xref: comp.soft-sys.matlab:802339

"James Tursa" wrote in message <l0slcm$ki8$>...
> "James Tursa" wrote in message <l0sjvm$50f$>...
> >  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);

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?