title: Passing a string variable between my c++ code to matlab
body: <p>I am new to matlab, and coding is not my job, I just use it for some side projects. So I don't really know what I am talking about, and I hope you'll understand that :)</p>
  
  <p>So I installed matlab on my computer and would like to use its libraries to plot some very simple graphs during the execution of my code (histograms, scatter plots, whatever). Plotting those graphs is not the first purpose of my code, I just find that easier to plot them during the execution rather than exporting them as a CSV file, and then plotting manually through excel.</p>
  
  <p>Question: I managed to make visual C++ "communicate" with matlab. I am passing some data using arrays, but I'd also like to pass a string (a path such as "C:\test\") as I'd like to automatically save those graphs once generated into a precise directory. I haven't found any way of doing it so far.</p>
  
  <p>Here is a bit of my c++ code, which is really simple:</p>
  
  <pre><code>Engine *ep;
  ep = engOpen(NULL);
  
  double *ArrayOne;
  double *ArrayTwo;
  
  const int  Asize = Area.size();
  
  ArrayOne = new double[Asize];
  ArrayTwo = new double[Asize];
  
  for (int i = 0; i &lt;= Area.size() - 1; i++) {
      ArrayOne[i] = Area[i][1];
      ArrayTwo[i] = Area[i][2] 
  }
  
  mxArray* ONE = mxCreateDoubleMatrix(Asize, 1, mxREAL);
  memcpy((void*)mxGetPr(ONE), (void*)ArrayOne, sizeof(double)*Asize);
  engPutVariable(ep, "one", ONE);
  
  mxArray* TWO = mxCreateDoubleMatrix(Asize, 1, mxREAL);
  memcpy((void*)mxGetPr(TWO), (void*)ArrayTwo, sizeof(double)*Asize);
  engPutVariable(ep, "two", TWO);
  
  engEvalString(ep, "plottest");
  
  delete[]ArrayOne;
  delete[]ArrayTwo;
  
  engClose(ep);
  </code></pre>
  
  <p>And the file Plottest.m:</p>
  
  <pre><code>h1= histogram(one);
  h1.EdgeColor = 'black';
  h1.FaceColor = 'white';
  hold on;
  h2 = histogram(two);
  h2.EdgeColor = 'blue';
  h2.FaceColor = [0.5 0.5 0.5];
  
  alpha(h1,.5);
  alpha(h2,.8);
  saveas(gcf,'C:\PhD\SVG2GMSH\SVG\test.png');
  </code></pre>
  
  <p>How can I replace my hard coded path into my m file ("C:\PhD\SVG2GMSH\SVG\test.png") by a more elegant variable that would contain it ?</p>
  
  <p>Thank you for your help. Also, let me know if you have any other suggestions in order to make my code look/work better :)</p>
  
  <p>Flo</p>