What probably happened in your case was that you were not typecasting the data to integer in matlab itself? You were passing it as it from matlab. The default data type in matlab is double. This means that you passed in a double matrix to your C mex function. Now when you use mxGetPr it returns you a double pointer. Now If you type cast this double pointer to int pointer, it is going to give you the wrong result when you dereference it because numbers are stored differently in floating point format and in integer fomat. Double uses 8 bytes normally while int uses 4. NOw when you derefernce the double pointer as int, it picks up first four bytes which correspond to only the sign bit and the exponent bits or maybe some precision bits but the complete number is not getting converted to int.
YOu possibly would have gotten the wrong result if you would have used mxGetData also without using the typecasting in matlab. Even though mxGetData returns a void pointer, the data actually is double so again by typecasting it as integer what I wrote above would happen.
The key thing to note in this is that you needed to typecast to integer in matlab itself before passing it to your C mex function.
"basudha pradhan" wrote in message <firstname.lastname@example.org>... > Thanks Dan for the suggestion. I tried mxGetdata but i got > this error when compiling the file. > > >> mex bitplan.c > Microsoft (R) Incremental Linker Version 7.10.3077 > Copyright (C) Microsoft Corporation. All rights reserved. > > C:\DOCUME~1\Owner\LOCALS~1\Temp\bitplan.obj > Creating library _lib3547.x and object _lib3547.exp > bitplan.obj : error LNK2019: unresolved external symbol > _mxGetdata referenced in function _mexFunction > bitplan.mexw32 : fatal error LNK1120: 1 unresolved > externals > > C:\PROGRAM FILES\MATLAB71\BIN\MEX.PL: Error: Link > of 'bitplan.mexw32' failed. > > ??? Error using ==> mex > Unable to complete successfully > >