BrancoBlace
Bioengineer
- Aug 8, 2007
- 2
Hey All,
I'm writting code to interface a matlab script with an algorithm based in C, and it seems to have a problem pasing data (in my case a 1D array) into the MEX function. Whenever i pass in the array to the MEX function the code knows that its an nth-element, 1D array but all the data values within the array get zero'ed out for whatever reason.
To try and debug the issue i removed my C algo from the picture and delt purely with the MatLab-to-C interface. Below is the code, without my algo, that exhibits this issue.
-----------------code--------------------
#include "mex.h"
#include "matrix.h"
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]){
double *xData;
int i, rows;
rows = mxGetN(prhs[0]);
xData = mxGetPr(prhs[0]);
for(i = 0; i < rows; i++){
printf("xData[%i] = %d\n", i, xData);
}
return;
}
----------------------------------------------
its a simple function that takes the array that gets passed into the MEX function and prints it to the matlab console.
To replicate this issue i would compile this .c file with the C compiler that comes with the MatLab R2007a rev. and would call this fucntion from the matlab command line with the follwoing command
>> testMex([1,2,3,4,5,6])
and it would output
xData[0] = 0
xData[1] = 0
xData[2] = 0
xData[3] = 0
xData[4] = 0
xData[5] = 0
>>
does anybody have any idea why the data values dont get transfered but the memory space/size does?
thx
I'm writting code to interface a matlab script with an algorithm based in C, and it seems to have a problem pasing data (in my case a 1D array) into the MEX function. Whenever i pass in the array to the MEX function the code knows that its an nth-element, 1D array but all the data values within the array get zero'ed out for whatever reason.
To try and debug the issue i removed my C algo from the picture and delt purely with the MatLab-to-C interface. Below is the code, without my algo, that exhibits this issue.
-----------------code--------------------
#include "mex.h"
#include "matrix.h"
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]){
double *xData;
int i, rows;
rows = mxGetN(prhs[0]);
xData = mxGetPr(prhs[0]);
for(i = 0; i < rows; i++){
printf("xData[%i] = %d\n", i, xData);
}
return;
}
----------------------------------------------
its a simple function that takes the array that gets passed into the MEX function and prints it to the matlab console.
To replicate this issue i would compile this .c file with the C compiler that comes with the MatLab R2007a rev. and would call this fucntion from the matlab command line with the follwoing command
>> testMex([1,2,3,4,5,6])
and it would output
xData[0] = 0
xData[1] = 0
xData[2] = 0
xData[3] = 0
xData[4] = 0
xData[5] = 0
>>
does anybody have any idea why the data values dont get transfered but the memory space/size does?
thx