Prev: Plot overlay
Next: Can't interface with parallel port
From: sakshi j on 6 Jul 2010 07:22 Hi, I have a small doubt.I have two functions in my mex file.one is the mexFunction.The other is called int test(int x).I call the test function from mexFunction.I would like to know if it is possible to use mexCallMATLAB within int test(int x). i.e is it possible to call mxCallMATLAB from within a function that is being called by mexFunction?? Thanks
From: sakshi j on 6 Jul 2010 08:01 "sakshi j" <sakshi399(a)yahoo.co.in> wrote in message <i0v3ks$gte$1(a)fred.mathworks.com>... > Hi, > I have a small doubt.I have two functions in my mex file.one is the mexFunction.The other is called int test(int x).I call the test function from mexFunction.I would like to know if it is possible to use mexCallMATLAB within int test(int x). > i.e is it possible to call mxCallMATLAB from within a function that is being called by mexFunction?? > Thanks THis is what i'm trying to run.The following code compiles but matlab crashes when i run it: //testptr.cpp #include<iostream> #include<cstdio> #include<mex.h> #include<stdlib.h> void test(double number) { double *n; int nlhs1, nrhs1; mxArray *plhs1[1], *prhs1[1]; nlhs1=1; nrhs1=1; n=mxGetPr(prhs1[0]); n[0]=number; mexCallMATLAB(nlhs1,plhs1,nrhs1,prhs1,"sqrt"); double p; p=mxGetScalar(plhs1[0]); printf("the square root is=%f",p); } void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] ) { double *num; num=mxGetPr(prhs[0]); double number; number=num[0]; test(number); //test(xp); /*int nlhs9, nrhs9; mxArray *plhs9[1], *prhs9[1]; nlhs9=1; nrhs9=1; prhs9[0]=mxDuplicateArray(prhs[4]); mexCallMATLAB(nlhs9,plhs9,nrhs9,prhs9,"sqrt"); int p; p=mxGetScalar(plhs9[0]); printf("the square root is=%d",p); */ return; }
From: James Tursa on 6 Jul 2010 10:10 "sakshi j" <sakshi399(a)yahoo.co.in> wrote in message <i0v5u9$h4l$1(a)fred.mathworks.com>... > "sakshi j" <sakshi399(a)yahoo.co.in> wrote in message <i0v3ks$gte$1(a)fred.mathworks.com>... > > Hi, > > I have a small doubt.I have two functions in my mex file.one is the mexFunction.The other is called int test(int x).I call the test function from mexFunction.I would like to know if it is possible to use mexCallMATLAB within int test(int x). > > i.e is it possible to call mxCallMATLAB from within a function that is being called by mexFunction?? Yes. You can call mexCallMATLAB (not mxCallMATLAB) from anywhere within your app. > THis is what i'm trying to run.The following code compiles but matlab crashes when i run it: > //testptr.cpp > > #include<iostream> > #include<cstdio> > #include<mex.h> > > #include<stdlib.h> > > void test(double number) > { > double *n; > int nlhs1, nrhs1; > mxArray *plhs1[1], *prhs1[1]; > nlhs1=1; > nrhs1=1; > n=mxGetPr(prhs1[0]); It crashes because prhs1[0] is garbage ... you haven't assigned it a valid mxArray * value. So you pass an invalid value to the mxGetPr function and you get a crash. You need to pass in a valid value for this or create one in the routine. James Tursa
|
Pages: 1 Prev: Plot overlay Next: Can't interface with parallel port |