title: How to make a MATLAB plot interactive?
body: <p>I'm trying to create a simple interface for plotting quadratic Lagrange polynomials. For this, you need just 3 points (with each their own x,y,z coordinates), which are then interpolated using the quadratic Lagrange polynomials.</p>
  
  <p>It's easy to make a static version, or even one that lets the user input the 3 points before plotting the curve. But it should also be possible for the user to drag an existing point in the plot window to another position, and then re-plot the curve automatically using the new position of this point!</p>
  
  <p><img src="https://i.stack.imgur.com/A8gCO.png" alt="enter image description here"></p>
  
  <p>So in short, the user should be able to drag these black dots to another location. After that (or while dragging), the curve should be updated.</p>
  
  <pre><code>function Interact()
  
  % Interactive stuff here
  
  figure();
  hold on;
  axis([0 7 0 5])
  
  DrawLagrange([1,1; 3,4; 6,2])
  
  function DrawLagrange(P)
  
  plot(P(:,1), P(:,2), 'ko--', 'MarkerSize', 10, 'MarkerFaceColor', 'k')
  
  t = 0:.1:2;
  Lagrange = [.5*t.^2 - 1.5*t + 1; -t.^2 + 2*t; .5*t.^2 - .5*t];
  
  CurveX = P(1,1)*Lagrange(1,:) + P(2,1)*Lagrange(2,:) + P(3,1)*Lagrange(3,:);
  CurveY = P(1,2)*Lagrange(1,:) + P(2,2)*Lagrange(2,:) + P(3,2)*Lagrange(3,:);
  
  plot(CurveX, CurveY);
  </code></pre>
  
  <p>I think I either have to use functions like <strong>WindowButtonDownFcn</strong>, <strong>WindowButtonUpFcn</strong> and <strong>WindowButtonMotionFcn</strong>, or the <strong>ImPoint</strong> from the Image Processing Toolbox. But how?</p>
  
  <p>[Edit]
  It should also work in 3D, since I'd like to generalize this concept to tensor product surfaces.</p>