title: Calling C++ function in Matlab, deal with 2-dimensional array, pointer of pointer?
body: <p>I am trying to call a function in C++ in Matlab, I thought I have written my functions properly. The function I want to call, looks like this, it has 8 arguments as input.</p>
  
  <pre><code>void LimitedPrice(double &amp;dMarketPosition, double** dmatLimitPrice, 
                    char* FileID, double* dvecOpen, double* dvecClose, 
                    double** dmatTempData, int tick, double dMaxBarBack)
   {Bla, Bla, Bla}
  </code></pre>
  
  <p>I want to get 2 values after running this function. Which stored in dMarketPosition, and dmatLimitPrice since they are pointers.</p>
  
  <p>In this function, I have to use some ** (double pointers) to represent my Matrix. </p>
  
  <p>After running this function, <strong>dMarketPosition, dmatLimitPrice</strong> will store what I want, since they are pointers. I have tested my function and I believed my function are written properly.</p>
  
  <p>Now I am ready to write my <strong>mexFunction()</strong>.
  My mex function somehow looks like this</p>
  
  <pre><code>void mexFunction(int nlhs, mxArray *plhs[],
               int nrhs,const mxArray *prhs[])
  {
      if(nrhs!=8){
            mexErrMsgIdAndTxt("LimitPrice: ","I want to 8 inputs");
      }
      // I want two output
      if(nlhs!=2) {
          mexErrMsgIdAndTxt("LimitPrice: ","I want to 2 outputs");
      }
  
     //The first input is a scalar
     double dmarketposition;
     dmarketposition = mxGetScalar(prhs[0]);
  
     //The second input is a 2-dimensional Matrix
     double **dmatlimitprice;
     *dmatlimitprice = mxGetPr(prhs[1]);
  
     /*****Assuming I have checked other inputs here properly*****/
     // I want to define my outputs
     // Create 1*1 matrix as output, which is the double value I want 
     plhs[0] = mxCreateDoubleMatrix(1,1,mxREAL);
     //The second output is a two dimensional matrix
     plhs[1] = mxCreateDoubleMatrix(2,(mwSize)4,mxREAL);
     dmarketposition = mxGetScalar(plhs[0]);
     *dmatlimitprice = mxGetPr(plhs[0]);
     // Call the function
     LimitedPrice(dmarketposition, dmatlimitprice, fileid,
     dvecopen, dvecclose, dmattempdata, tick, dmaxbarback);
  }
  </code></pre>
  
  <p>The above function does not seem to work... It seems that in mexFunction(),
  We would better only pass one-dimensional array, which is double *a like thing.</p>
  
  <p>My key issue is <strong>"How can we deal with 2-dimensional array, which is a matrix"</strong> in mexFunction().</p>