Changes between Version 8 and Version 9 of adherelinux/mex
- Timestamp:
- Jul 17, 2010, 9:23:44 PM (14 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
adherelinux/mex
v8 v9 26 26 void mexFunction(int nlhs, mxArray *plhs[],int nrhs, const mxArray *prhs[]) 27 27 { 28 int i, j, mA, nA, mB, nB, nMatSize; 29 double *A, *B, *C; 30 /*input_check */ 28 int i, j, mA, nA, mB, nB, nMatSize;[[br]] 29 double *A, *B, *C;[[br]] 30 /*input_check */[[br]] 31 31 if (nrhs != 2) 32 32 mexErrMsgTxt("The input must 2"); 33 33 if (nlhs != 1) 34 mexErrMsgTxt("The input must 1"); 35 mA = mxGetM(prhs[0]); 36 nA = mxGetN(prhs[0]); 37 mB = mxGetM(prhs[1]); 38 nB = mxGetN(prhs[1]); 34 mexErrMsgTxt("The input must 1");[[br]] 35 mA = mxGetM(prhs[0]);[[br]] 36 nA = mxGetN(prhs[0]);[[br]] 37 mB = mxGetM(prhs[1]);[[br]] 38 nB = mxGetN(prhs[1]);[[br]] 39 39 40 printf("mA= %d\n",mA); 41 if (mA != mB ||nA != nB) 42 mexErrMsgTxt("The size must identical") ; 40 printf("mA= %d\n",mA); [[br]] 41 if (mA != mB ||nA != nB) [[br]] 42 mexErrMsgTxt("The size must identical") ; [[br]] 43 43 44 44 /*output to buffer*/[[br]] 45 45 plhs[0]=mxCreateDoubleMatrix(mA,nA,mxREAL);[[br]] 46 46 /*get value*/[[br]] 47 A = mxGetPr(prhs[0]); 48 B = mxGetPr(prhs[1]); 49 C = mxGetPr(plhs[0]); 50 /*sum*/ 51 nMatSize = mA * nA; 52 for (i=0; i<nMatSize; i++) 53 { 47 A = mxGetPr(prhs[0]);[[br]] 48 B = mxGetPr(prhs[1]);[[br]] 49 C = mxGetPr(plhs[0]);[[br]] 50 /*sum*/[[br]] 51 nMatSize = mA * nA;[[br]] 52 for (i=0; i<nMatSize; i++){ 54 53 C[i] = A[i] + B[i]; 55 }56 /*result*/ 54 }[[br]] 55 /*result*/[[br]] 57 56 mexPrintf("ending"); 58 57 } 59 58 60 how to compile and run 61 > mex add.c62 > a = [1 2 3 4];63 > b = [1 2 3 4];64 > c = add(a,d)65 mA=1 66 ending 67 c = 68 2 4 6 8 59 how to compile and run 執行MATLAB程式在命令端下 60 > mex add.c [[br]] 61 > a = [1 2 3 4]; [[br]] 62 > b = [1 2 3 4]; [[br]] 63 > c = add(a,d) [[br]] 64 mA=1 [[br]] 65 ending [[br]] 66 c = [[br]] 67 2 4 6 8 [[br]] 69 68 70 69