title: How to save a variable from within the integration with ode113?
body: <p>I have an ODE to be integrated with <code>ode113</code>. Inside the function that describes the derivatives I compute some variables that I would like to "save" (either store into a file or into an array). How can I do that?</p>
  
  <p>Here is an example (adapted from the documentation). Run the following script:</p>
  
  <pre><code>global number_of_calls
  number_of_calls = 0;
  
  [t, y] = ode113(@myfunc, [0 10], 0);
  plot(t,y,'-o')
  fprintf('Number of calls of ''myfunc'': %d\n', number_of_calls)
  fprintf('Number of elements of ''t''  : %d\n', length(t))
  </code></pre>
  
  <p>which calls the function containing the ODE to be integrated:</p>
  
  <pre><code>function dydt = myfunc(t, y)
  
  global number_of_calls
  
  dydt = 2*t;
  a = 2*y; % &lt;--- how can I save a?
  
  number_of_calls = number_of_calls + 1;
  
  end
  </code></pre>
  
  <p>I thought of writing to file the values of <code>a</code> from inside <code>myfunc</code>, but as you can see <code>myfunc</code> is called multiple times before actually storing the current value for the independent variable, <code>t</code>, and in the end I would have two arrays <code>a</code> and <code>t</code> of different size. </p>