title: Import 3D array from MAT-file using C++
body: <p>I would like to know if there is a way to know the 'z' dimension of a 3D array when reading data from a 'MAT-file' using the MATLAB API. I've implemented a function to load the data from file as follows:</p>
  
  <pre><code>double* importMATFile(const char* i_file)
  {
      MATFile *pMF;
      // open MAT-file
      pMF = matOpen(i_file, "r");
      // check for file errors
  
      // Matlab Array Data
      mxArray *mArrayData;
      // Matlab Variable Name
      const char* mVarName = NULL;
      // read data from file
      mArrayData = matGetNextVariable(pMF, &amp;mVarName);
  
      // pointer to mxArray data
      double *dataPtr; 
      dataPtr = (double*) mxGetPr(mArrayData);
  
      // NOTE MATLAB work in COLUMN-MAJOR order
  
      // dimension of the array : rows
      int32_t NROWS = mxGetM(mArrayData);
      // Right now the z dimension must be known a priori
      int32_t NDEPTH = 32
      // dimension of the array : cols
      int32_t NCOLS = mxGetN(mArrayData) / NDEPTH;
  
      return dataPtr;
  }
  </code></pre>
  
  <p>I'm stuck when getting the DEPTH value, in order to know the number of columns. I've have noticed that the result of the function <strong>mxGetNumberOfDimensions(mArrayData)</strong> is <strong>3</strong>, so, the API knows there are three dimensions.</p>