From: sakshi j on 23 Jun 2010 09:25 Hi, I'm trying to run the following piece of code: void mexFunction( int nlhs, mxArray *[], int nrhs, const mxArray *prhs[] ) { using namespace libbase; vector <double> y; double *xValues; int i,j; mxArray *value; xValues = mxGetPr(prhs[0]); int rowLen = mxGetN(prhs[0]); int colLen = mxGetM(prhs[0]); y.init(2); y=0; y(1)=3; y(2)=3; printf("the rowlength is=%d",rowLen); value = mxDuplicateArray(prhs[0]); double neigh[] = {3,3}; double *pr; mxArray *p; int nlhs1, nrhs1; mxArray *plhs1[2], *prhs1[2]; nlhs1 = 2; nrhs1 = 2; prhs1[0]=value; prhs1[1] = mxCreateCellMatrix(2, 1); pr = mxGetPr(prhs1[1]); for( i=0; i<=1; i++ ) { pr[i] = neigh[i]; } mxSetCell(*p,1, ); mexCallMATLAB(nlhs1,plhs1,nrhs1,prhs1,"wiener2"); return; } i first run the following: a = im2double(imread('stego.tif'))' Then i compile my mex file. And I recieve the following output with this error: the rowlength is=256the value of neigh is=0.000000the value of neigh is=3.000000??? Error using ==> ones Size vector must be a row vector with real elements. Error in ==> wiener2 at 55 localMean = filter2(ones(nhood), g) / prod(nhood); Can anybody help me in this regard?
From: James Tursa on 23 Jun 2010 18:45 "sakshi j" <sakshi399(a)yahoo.co.in> wrote in message <hvt200$c85$1(a)fred.mathworks.com>... : > value = mxDuplicateArray(prhs[0]); : > prhs1[0]=value; FYI, you don't need to duplicate prhs[0] for use in prhs1[0], you can just do this instead: prhs1[0] = prhs[0]; and then get rid of the value = mxDuplicateArray(prhs[0]) line. > prhs1[1] = mxCreateCellMatrix(2, 1); > pr = mxGetPr(prhs1[1]); > for( i=0; i<=1; i++ ) { > pr[i] = neigh[i]; > } > > mxSetCell(*p,1, ); You should not be using mxGetPr on a cell array. So the pr = mxGetPr(prhs1[1]) line makes no sense. If you are trying to fill the cells of prhs1 with mxArrays that contain the neigh values, then you need to create the mxArrays and then use mxSetCell with them. e.g., prhs1[1] = mxCreateCellMatrix(2, 1); for( i=0; i<=1; i++ ) { p = mxCreateDoubleScalar(neigh[i]); mxSetCell( prhs1[1], i, p ); } James Tursa
From: sakshi j on 6 Jul 2010 07:16 "James Tursa" <aclassyguy_with_a_k_not_a_c(a)hotmail.com> wrote in message <hvu2q2$t4o$1(a)fred.mathworks.com>... > "sakshi j" <sakshi399(a)yahoo.co.in> wrote in message <hvt200$c85$1(a)fred.mathworks.com>... > : > > value = mxDuplicateArray(prhs[0]); > : > > prhs1[0]=value; > > FYI, you don't need to duplicate prhs[0] for use in prhs1[0], you can just do this instead: > > prhs1[0] = prhs[0]; > > and then get rid of the value = mxDuplicateArray(prhs[0]) line. > > > prhs1[1] = mxCreateCellMatrix(2, 1); > > pr = mxGetPr(prhs1[1]); > > for( i=0; i<=1; i++ ) { > > pr[i] = neigh[i]; > > } > > > > mxSetCell(*p,1, ); > > You should not be using mxGetPr on a cell array. So the pr = mxGetPr(prhs1[1]) line makes no sense. If you are trying to fill the cells of prhs1 with mxArrays that contain the neigh values, then you need to create the mxArrays and then use mxSetCell with them. e.g., > > prhs1[1] = mxCreateCellMatrix(2, 1); > for( i=0; i<=1; i++ ) { > p = mxCreateDoubleScalar(neigh[i]); > mxSetCell( prhs1[1], i, p ); > } > > James Tursa Thanks James, i have another doubt.is it possible to call mxCallMATLAB from outside the mex-function? for instance i have two functions in my mex file: mexFunction and a function called int test(int x). I call test from mexFunction.But is it possible to execute a MATLAB function say "sqrt(x)" from int test(int x)?? I have tried it and it says segmentation violation. Thanks again Sakshi
|
Pages: 1 Prev: mexCallMATLAB Next: How to plot shapefile onto a regular x-y plot |