title: Embedding octave in c++ - How to pas a variable sized vector
body: <p>I'm trying to embed the Octave interpreter in C++, and the m files that will be called will always be of this type...</p>
  <pre><code>function out = myFunction(pars, val1, val2)
  
  % pars will always be a variable sized row vector of doubles
  % val1 will always be a 1 x 1 double
  % val2 will also be a  1 x 1 double
  
  % out will always be a [n x 3] array e.g
  
  out = [1 2 3 ; 4 5 6 ; 7 8 9];
  
  endfunction
  
  </code></pre>
  <p>I have sort of got this working but only if I pass a single value for pars. So, if I have in as an octave_value_list, then</p>
  <pre><code>
  
  double pars = 10;
  double bulkIn = 20;
  double bulkOut = 30;
  
  octave_value_list in;
  in(0) = pars;
  in(1) = bulkIn;
  in(2) = bulkOut;
  
  octave_value_list out = octave::feval(&quot;myFunction&quot;, in);
  
  </code></pre>
  <p>..this works. What I can't figure out is how to put an array into in(0). I've tried the approach below, but if fails because &quot;no known conversion for argument 1 from 'std::vector&lt;double? to const octave_value&amp;&quot;</p>
  <p>Eventually, pars will come in to octaveCallerFunction as an argument of std::vector  from 'main'. So my question is how do I correctly get a variable sized row vector into in(0)?</p>
  <pre><code>#include &lt;iostream&gt;
  #include &lt;oct.h&gt;
  #include &lt;octave.h&gt;
  #include &lt;parse.h&gt;
  #include &lt;interpreter.h&gt;
  #include &lt;vector&gt;
  
  using namespace std;
  
  int octaveCallerFunction() {
  
      static int started = 0;
      static octave::interpreter interpreter;
  
      // check to see if the interpreter has started
      // and initialise it if not.
      if (started == 0) {
          interpreter.initialize_history(false);
          interpreter.initialize();
          interpreter.execute();
          string path = &quot;&lt;the relevant path goes here&gt;&quot;;
          octave_value_list p;
          p(0) = path;
          octave_value_list o1 = octave::feval (&quot;addpath&quot;, p, 1);
          cout &lt;&lt; &quot;In interpreter initialise loop&quot; &lt;&lt; endl;
          started = 1;
      }
  
      octave_value_list in;
  
      vector&lt;double&gt; pars = {1, 2, 3, 4};
  
      double bulkIn = 2.073e-6;
      double bulkOut = 6.35e-6;
  
      in(0) = pars;
      in(1) = octave_value(bulkIn);
      in(2) = octave_value(bulkOut);
  
      octave_value_list out = octave::feval (&quot;myFunction&quot;, in, 1);
  
      if (out.length () &gt; 0)
        std::cout &lt;&lt; &quot;Output is &quot;
                  &lt;&lt; out(0).matrix_value(0)
                  &lt;&lt; std::endl;
      else
        std::cout &lt;&lt; &quot;invalid\n&quot;;
  
      return 0;
  }
  
  int main(void) {
  
  
      octaveCallerFunction();
      return 0;
  }
  </code></pre>