Changes between Version 8 and Version 9 of adherelinux/mex


Ignore:
Timestamp:
Jul 17, 2010, 9:23:44 PM (14 years ago)
Author:
adherelinux
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • adherelinux/mex

    v8 v9  
    2626void mexFunction(int nlhs, mxArray *plhs[],int nrhs, const mxArray *prhs[])
    2727{
    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]]
    3131  if (nrhs != 2)
    3232    mexErrMsgTxt("The input must 2");
    3333  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]]
    3939
    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]]
    4343
    4444  /*output to buffer*/[[br]]
    4545  plhs[0]=mxCreateDoubleMatrix(mA,nA,mxREAL);[[br]]
    4646  /*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++){
    5453      C[i] = A[i] + B[i];
    55     }
    56   /*result*/
     54  }[[br]]
     55  /*result*/[[br]]
    5756  mexPrintf("ending");
    5857}
    5958
    60 how to compile and run
    61 >mex add.c
    62 >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
     59how 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]]
     64mA=1 [[br]]
     65ending [[br]]
     66c = [[br]]
     672 4 6 8 [[br]]
    6968
    7069