File Exchange

image thumbnail

zoom2cursor

version 1.0.0.0 (3.76 KB) by Brett Shoelson
Dynamic, scalable zoom following the motion of the cursor; also displays the current position.

3 Downloads

Updated 19 Feb 2003

View License

Editor's Note: This file was a File Exchange Pick of the Week

% FUNCTION ZOOM2CURSOR
% 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.
%
% BUTTON CLICKS:
% 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. (shoelson@helix.nih.gov, shoelson@hotmail.com)
% 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)

Cite As

Brett Shoelson (2021). zoom2cursor (https://www.mathworks.com/matlabcentral/fileexchange/2902-zoom2cursor), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (19)

Brett Shoelson

@Harsha:
The buttondown actions are defined in sub-function bdfcn(); you can overwrite whatever you want there. (Left = 'normal', Right = 'alt', Middle = 'Extend'. However, the function will no longer do what it was designed to do if you change those. I'm not sure what exactly you're trying to do, but I would imagine that there's a better way to do it than by editing this function.
Good luck,
Brett

Harsha K

Hi Brett,

I would like to disable the left-click and right-click and middle-button functions while using zoom2cursor, how can I do that. I want those buttons to function either as to how I would define them or their default functioning.

Best,
HK

Brett Shoelson

@ Ramon, David, kukke, others...
This file is quite old, and I haven't updated it in 16 years. It seems that it has become buggy and unreliable. I will try to circle back to address some issues, but in the meantime I'm afraid I can't warranty this tool. Sorry!
Brett

Ramon Ticzon

how to use this code? Sorry I am new to Matlab. Thanks!

Brett Shoelson

@kukke:
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.

Regards,
Brett

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

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:

m=zeros(200);
m(50,125)=1;
figure;
imagesc(m);
colormap(gray);
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?

Brett Shoelson

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

Mohammed El-Said

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

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)
return;
end;
set(gcf,'windowbuttonmotionfcn',zoomparams.oldwbmf);
set(zoomparams.currax,'units',zoomparams.oldaxunits,'xlim',zoomparams.oldxlim,'ylim',zoomparams.oldylim);
set(get(zoomparams.currax,'children'),'buttondownfcn',zoomparams.bdfcnold,'busyaction',zoomparams.baold);
set(gcf,'pointer',zoomparams.oldpointer,'doublebuffer',zoomparams.dbold);

Ahmad Samy

Excellent usage of figure handles.
Waiting for your next work

Moshe Ufnik

Very elegant

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?

paul calvert

VERY VERY VERY nice!!
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....

Plamen Stoyanov

Anne Carpenter

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

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.

Berthold Käferstein

Very cool utility to simplify the work with plots!

Paul Koola

Excellent feature for Visual data exploration.

MATLAB Release Compatibility
Created with R13
Compatible with any release
Platform Compatibility
Windows macOS Linux
Acknowledgements

Inspired: zinput

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!