title: Matlab: Using interp2 in ode45
body: <p>I have a 2-dimensional matrix with discrete values and I want to use the ode45 command.
  To do this I used interp2 to create a function ode45 can use.</p>
  
  <p>The problem is, it looks like ode45 is moving out of my defined area and so interp2 returns NaN-values. To get rid of the NaN I used an extrapolation value but now it seems that ode45 integrates from my initial values to this extrapolation value, disregarding any of my given values in the matrix.</p>
  
  <p>Here is a little example with a 2x2 matrix:</p>
  
  <pre><code>clear all;
  close all;
  clc;
  
  A = rand(2, 2);              % the matrix with my values
  x = 1:2;         
  y = x;
  [X, Y] = meshgrid(x, y);     % grid on which my values are defined
  xi = 1:0.5:2;              
  yi = xi;
  [Xi, Yi] = meshgrid(xi, yi); % interpolation grid
  
  tspan = 0:0.2:1;
  
  B = @(xq,yq)interp2(X, Y, A, xq, yq, 'linear', 10);   % interpolation function with extrapval of 10
  
  [T,C] = ode45(@(Xi,Yi)B(Xi,Yi), tspan, [Xi,Yi]);       % ode45 function using interp-function and intital values [Xi,Yi]
  </code></pre>
  
  <p>What am I doing wrong?
  Thanks for any help in advance!</p>