title: Obtaining approximate derivatives with variable x spacing in MATLAB?
body: <p>I have two arrays: <code>x</code> and <code>y</code>. In practice, <code>y</code> is dependent on <code>x</code>, but both arrays are measured values. I would like to obtain the derivative of <code>y</code> with respect to <code>x</code>. If <code>x</code> were uniformly spaced (i.e. <code>x=[1 2 3 4 5]</code>), I could do something with <code>diff</code> like <a href="http://www.mathworks.com/help/matlab/ref/diff.html#btw_sz6-1" rel="nofollow">this</a>:</p>
  
  <pre><code>h = 0.001;
  x = -pi:h:pi;
  f = sin(X);
  y = diff(f)/h;
  </code></pre>
  
  <p><strong>However, x is not uniformly spaced</strong> (i.e. <code>x=[1 1.9 2.8 4.1]</code>). How can I obtain the partial derivative of this data set?</p>