title: MATLAB - How to zoom in to mouse position
body: <p>have an image that I would like to zoom in/out when I left/Right-click a point on the image but I do not want to do it using the magnifying glass. Basically, I need a script for what I said above. I have come up with the following script but it only zooms in/out to the center not to the position that I click on.</p>
  
  <p>And if you are asking why I am getting the clicked position using <code>ginput</code> the answer is, I am planning to use this script to edit a binary image! I have removed the lines corresponding to the binary image editing part to avoid any confusion.</p>
  
  <pre><code>hFi= figure; imshow(e);
  
  button=0;
  
  while button~=2
      % Get the mouse position on the axes (needed for binary image editing) and button number
      [y,x,button]=ginput(1);
  
      % Get the mouse position on the figure
      position=get(hFi,'CurrentPoint')
  
      % Set 'CurrentPoint' to the mouse position that was just captured
      set(hFi,'CurrentPoint',position)
  
      % Determine if it is a zoom-in or zoom-out
      if button==1
          zoom(2);
      elseif button==3
          zoom(0.5);
      end
  
  end
  </code></pre>
  
  <p>I think the command <code>set()</code> does not do anything here but I saw someone suggested that in a forum. Sorry if that looks dumb!</p>