C MEX file issue in for loop
Show older comments
Hi, I have a MEX file which transmits data to MCC DAQ. My data is 128x160 double values. But I am not receiving the full output matrix. I have attached the mat file of output variable b. Please give your suggestions.
int analogoutputMatlab(double* data,double* b,int M,int N)
{
int i,j;
int BoardNum = 0;
int ULStat = NOERRORS;
for (j=0;j<M;j++) %M is number of rows, M=128
{
for (i=0;i<N;i++) %N is number of columns, N=160
{
ULStat = cbAOut(BoardNum, Chan1, Range, data[j,i]); %pushing the data to analog output pin of DAQ
ULStat = cbAIn(BoardNum, Chan, Range, &data[j,i]); %receiving the same data via the analog input pin
b[j,i] = data[j,i];
}
}
return 0;
}
void mexFunction( int nlhs, mxArray *plhs[],int nrhs, const mxArray *prhs[] )
{
double *a;
int M,N;
double* b;
const mwSize *dims;
/* Check for proper number of arguments. */
if(nrhs!=1) {
mexErrMsgTxt("one input required.");
}
else if(nlhs!=1) {
mexErrMsgTxt("one output arguments required.");
}
/* get dimensions of the input matricies */
dims=mxGetDimensions(prhs[0]);
M=(int)dims[0];
N=(int)dims[1]; //m and n is 1x256
mexPrintf("m and n is %d %d",M,N);
/* create a pointer to the real data in the input matricies */
a=mxGetData(prhs[0]);
/* create the output matricies */
plhs[0] = mxCreateDoubleMatrix((mwSize)M,(mwSize)N,mxREAL);
b = mxGetPr(plhs[0]);
analogoutputMatlab(a,b,M,N);
}
I think the for loop outputs data columnwise and it only outputs 160 data values. I need to transmit 128x160 data. Please give your suggestions
Accepted Answer
More Answers (0)
Categories
Find more on Write C Functions Callable from MATLAB (MEX Files) in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!