From: Feixiong on 19 Jan 2010 08:44 Hello, I am now using gateway functions to call c function to speedup the program and encounterimh some problem. I am a new to matlan and c. hope you can help me! void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]){ .... long int *arg_val; arg_va = (long int *) mxGetPr(prhs[0]); ..... } i am wondering after the type change why the content is set to be zero. Thanks
From: James Tursa on 19 Jan 2010 09:43 "Feixiong " <f.liao(a)tue.nl> wrote in message <hj4cv4$nfh$1(a)fred.mathworks.com>... > Hello, > I am now using gateway functions to call c function to speedup the program and encounterimh some problem. I am a new to matlan and c. hope you can help me! > > void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]){ > ... > long int *arg_val; > arg_va = (long int *) mxGetPr(prhs[0]); > .... > } > > i am wondering after the type change why the content is set to be zero. > > Thanks mxGetPr returns a double *. Changing this to a long int * doesn't look right. What is the type of variable that you are calling the mex function with? int32? Or what? Usually one would do this instead: int *arg_val; arg_va = (int *) mxGetData(prhs[0]); But the above works only if the int is a 32-bit integer and prhs[0] is a class int32 variable. If you are actually trying to convert a double input into an int in the C code, you would do this: int arg_val; arg_va = *mxGetPr(prhs[0]); You need to clarify what you are actually intending to do. James Tursa
From: Feixiong on 19 Jan 2010 10:00 > mxGetPr returns a double *. Changing this to a long int * doesn't look right. What is the type of variable that you are calling the mex function with? int32? Or what? Usually one would do this instead: > > int *arg_val; > arg_va = (int *) mxGetData(prhs[0]); > > But the above works only if the int is a 32-bit integer and prhs[0] is a class int32 variable. If you are actually trying to convert a double input into an int in the C code, you would do this: > > int arg_val; > arg_va = *mxGetPr(prhs[0]); > > You need to clarify what you are actually intending to do. > > James Tursa hi James, what i am intending to do is: prhs[0]) contains a n-length of 1-D array of integer numbers, which is the index of another 2-D array input prhs[1]). But after mxGetdata or mxGetpr, prhs[0]) was changed to double, which is can't be used as index directly. Thanks, is there any solution for this?
From: Stefan on 19 Jan 2010 10:05 How about this: void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]){ long int *arg_val; double *arg_ret; // computation .... arg_ret = mxGetPr(prhs[0]); *arg_ret = (double) *arg_val; } Regards, Stefan
From: Stefan on 19 Jan 2010 10:10 Ah, right hand side ... to use it for indexing you need to dereference somewhere. There you can cast it to integer. Or simply make a copy with the appropriate type. Regards, Stefan "Feixiong " <f.liao(a)tue.nl> wrote in message <hj4he6$fra$1(a)fred.mathworks.com>... > > > mxGetPr returns a double *. Changing this to a long int * doesn't look right. What is the type of variable that you are calling the mex function with? int32? Or what? Usually one would do this instead: > > > > int *arg_val; > > arg_va = (int *) mxGetData(prhs[0]); > > > > But the above works only if the int is a 32-bit integer and prhs[0] is a class int32 variable. If you are actually trying to convert a double input into an int in the C code, you would do this: > > > > int arg_val; > > arg_va = *mxGetPr(prhs[0]); > > > > You need to clarify what you are actually intending to do. > > > > James Tursa > > hi James, > > what i am intending to do is: > prhs[0]) contains a n-length of 1-D array of integer numbers, which is the index of another 2-D array input prhs[1]). > > But after mxGetdata or mxGetpr, prhs[0]) was changed to double, which is can't be used as index directly. > > Thanks, is there any solution for this?
|
Next
|
Last
Pages: 1 2 3 Prev: Solving a system of equations in Simulink Next: changing color in a plot |