[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Problem with mex file
From: 
frank wang 
Subject: 
Re: Problem with mex file 
Date: 
Sat, 9 Sep 2006 14:16:32 0700 
Hi, John,
It is strange. The problem codes are:
if (nRhs > 1)
{
px = mxGetPr(pRhs[1]);
for (n=0; n<mxGetM(pRhs[1])*mxGetN(pRhs[1]); n++)
pScl[n] = (unsigned)px[n];
px = mxGetPr(pRhs[2]);
pScl[5] = (unsigned)px[0];
px = mxGetPr(pRhs[3]);
pScl[6] = (unsigned)px[0];
}
where pScl is initialized to {0 0 0 0 0 0}.
The following commands work in Matlab:
y=fft_mx1(rand(1024,1));
y=fft_mx1(rand(1024,1),0,0,0);
y=fft_mx1(rand(1024,1),[0 0]);
y=fft_mx1(rand(1024,1),[0 0,0]);
y=fft_mx1(rand(1024,1),[0 0,0],0);
y=fft_mx1(rand(1024,1),[0 0,0],0,0);
However, the following two does not:
y=fft_mx1(rand(1024,1),0);
y=fft_mx1(rand(1024,1),0,0);
I just want to let you know this and to make Octave even better.
Thanks
Frank
On 9/8/06, John W. Eaton <address@hidden> wrote:
On 8Sep2006, frank wang wrote:
 I use the mkoctfile mex to compile the c code and it works great. Thanks.

 However, when I run the code with fewer input, it will cause segment fault.
 It is caused by function mxGetPr. For example, if in the c code, I have
 px=mxGetPr(pRhs[3]). But I only passed 2 parameters, this will cause segment
 fault. I fix this by changing my c code. But I just want to point it out
 since in Matlab it works.
Why should it work? If you pass two parameters, then the values are
in prhs[0] and prhs[1]. Anything beyond that is going to be garbage
anyway. Maybe it is just dumb luck that it works in Matlab?
jwe