title: Matlab API reading .mat file from c++, using STL container
body: <p>I have to read some .mat data files from c++, I read through the documentation, but I would like to know how to handle the data in a clean and elegant way, e.g. using std:vector(modest .mat file size(10M~1G), but memory issues should be taken seriously)</p>
  
  <p>My function is sth like:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include "mat.h"
  #include &lt;vector&gt;
  
  int matread(const char *file, const vector&lt;double&gt;&amp; pdata_v) {
  
  MATFile *pmat;
  
  pmat=matOpen("data.mat","r");
  if (pmat == NULL) {
      printf("Error opening file %s\n", file);
      return(1);
  }
  mxArray *pdata = matGetVariable(pmat, "LocalDouble");
  
  // pdata -&gt; pdata_v
  
  mxDestroy pa1;  // clean up
  return 0;
  }
  </code></pre>
  
  <p>so, the question is, how can I make a copy from mxArray *pdata array to vector pdata_v efficiently and safely?</p>