View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from

4.8 | 12 ratings Rate this file 8 Downloads (last 30 days) File Size: 3.76 KB File ID: #2902 Version: 1.0
image thumbnail



Brett Shoelson (view profile)


02 Jan 2003 (Updated )

Dynamic, scalable zoom following the motion of the cursor; also displays the current position.

Editor's Notes:

This file was a File Exchange Pick of the Week

| Watch this File

File Information

% ZOOM2CURSOR, without arguments, will activate the current axis, create a text box showing the current position of the mouse pointer (similar to pixval), and automatically zoom the image to the location of the cursor as it is moved. The zoomed display dynamically scrolls with the motion of the cursor.
% By default, the function zooms to 50% of the image in the axis.
% Left-clicking will zoom in further, and right-clicking will zoom out.
% Shift-clicking (or simultaneously clicking the left and right mouse buttons) at any point will display the original (un-zoomed) image, as will moving the cursor outside of the current axis. The zoom percentage is restored when the mouse is moved.
% Double-clicking zooms out to the original image, modifying the zoom percentage.
% Tested under R12.1 and R13.
% Written by Brett Shoelson, Ph.D. (,
% 12/26/02
% 2/16/03; Rev 2: Program is more robust; fixes a bug when window is resized.
%Incremental increase/decrease in zoom percent (on mouseclick) has been reduced.
%ALSO: Now works with images, surfaces, lines (and thus plots), and patches (rather than just images)


This file inspired Zinput.

MATLAB release MATLAB 6.5 (R13)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (15)
13 May 2016 Brett Shoelson

Brett Shoelson (view profile)

Thanks for the feedback. I hadn't touched this file in many years--glad you're finding it useful. Regarding your request...It took me about two minutes to modify the file to allow the specification of axes to activate. Happy to send it to you if you send me your address.


Comment only
10 May 2016 kukke swaroop

Great feature! Amazing work.
It ll be useful if it can hover and zoom on figure containing subplots. it works only for the last subplot

14 Aug 2012 David Aronstein

This way to interact with data is fantastic, truly a wonderful contribution!

I think there is a bug, or perhaps a false expectation on my part. In MATLAB 2012a on a Mac, I create a simple image and investigate it zoom2cursor:


The one white pixel in the matrix is at (50,125) but using zoom2cursor it reports the pixel to be at ~(64,117). Thoughts about this?

01 Apr 2011 Brett Shoelson

Brett Shoelson (view profile)

Thanks for all the feedback.... Regarding EXIT functionality, doesn't clicking on the "x" (lower left) suffice?

Comment only
25 Mar 2011 Mohammed El-Said

Great work,
it is really useful,
Thanks for Sharing...

06 Oct 2009 Charles Attard

Very useful, thanks.
For those wondering how to exit the function, just click on 'X'.

I've found useful to create a 'exit_zoom2cursor' function.
If you're interested, comment the statement 'endbutton = ...'
And call this function:

function exit_zoom2cursor
zoomparams = getappdata(gcf,'zoomparams');
if isempty(zoomparams)

Comment only
29 Nov 2007 Ahmad Samy

Excellent usage of figure handles.
Waiting for your next work

23 Sep 2007 Moshe Ufnik

Very elegant

25 Apr 2006 Engamba Bobin

Very good work. Will help me greatly.
How do you exit, assuming you can? Or do you just have to close the figure?

09 Nov 2005 paul calvert

A nice improvement would be to have an 'escape' mode to allow selecting a different figure or subplot ..or just plain 'exit' of the function....

17 Jun 2005 Plamen Stoyanov

29 Sep 2004 Anne Carpenter

Nice work! Just what I needed, and it works great on R14 on a Mac.

09 Jun 2004 Andy Bliss

Very nice! I was contemplating writing something like this, but I was glad to find that someone else had already accomplished the daunting task.

14 Jul 2003 Berthold Käferstein

Very cool utility to simplify the work with plots!

26 Apr 2003 Paul Koola

Excellent feature for Visual data exploration.

Contact us