File Exchange

image thumbnail

ginput2.m v3.1 (Nov 2009)

version (7.49 KB) by Carlos Adrian Vargas Aguilera
Same as GINPUT but with ZOOM, PAN and (optionally) PLOT and image SCALE/GEOREFERENCE!


Updated 12 Nov 2009

View Version History

View License

Do you still use GINPUT to graphically select points on current axes with the mouse? Try this one!

With GINPUT2 you can also:
1. ZOOM: in, out (double-click)!
2. PAN: when dragging!
3. DELETE: last selected point!
4. PLOT: while selecting! (optional, just input the line style!)
5. SCALE or GEOREFERENCE images! (optional, just input: true)

So, besides of selecting points in a more precise way (zooming) you can DIGITIZE(!!!) lines with the last two options, by simply using:
>> ginput2(true,'.k')

Enjoy it!
Bug reports and comments will be very appreciated!

Cite As

Carlos Adrian Vargas Aguilera (2020). ginput2.m v3.1 (Nov 2009) (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (16)

Sami Abou-Kebeh LLano

I found another bug regarding the pan and zoom.
Solved applying the previous changes and changing this block (line 533 and on):

% Checks if ZOOM IN with PAN:
if ismember(button,ZOOMIN) && ~outside
% Dragging rectangle:
undoPtrFig = gcf;
ydrag = get(gca,'CurrentPoint');
x_ini = ydrag(1,1);
y_ini = ydrag(1,2);
xdrag = ydrag(1,1)-x;
ydrag = ydrag(1,2)-y;
% Do the PANNING:
%if any(abs([xdrag ydrag])>eps*1000000)
if or(and(abs(xdrag) > .1,abs(ydrag) < .1),and(abs(ydrag) > .1,abs(xdrag) < 0.1))
% Only PAN (dragging):
lim(1:4) = lim(1:4) - [xdrag xdrag ydrag ydrag];
% PAN (centers the last point) and ZOOM in:
% lim = [x+diff(lim(1:2))/2*[-1 1] y+diff(lim(3:4))/2*[-1 1]];
% axis(lim)
% zoom(2)
lim(1:4) = [min(x,x_ini) max(x,x_ini) min(y,y_ini) max(y,y_ini)];

Luca Amerio

DThere are several bugs in 2017b.
For example line 611 should be

if all((lim~=zlim(1:4)))

line 586 should be

if iscell(hlastaxes), hlastaxes = [hlastaxes{:}]; end

Despite this, the lines plotted still originate always from the first point (resulting in a "fan" rather than a poly-line). I still haven't found the source of this bug, but the code clearly needs to be updated to most recent versions (it looks as it has been abandoned about 10 years ago)


Andrew, I had the same issue in Matlab 2017b and did not have it in Matlab 2012a which I have to use at work.
I deactivated the rezoom part in the code as GagoX described, because I found that part of the code annoying for my purpose. Coincidentally this also solved the issue you described.

Andrew Meier

Zooming works fine but I get the following error when trying to select a point with right click:

>> plot(1:10)
>> ginput2(1)

[[[[[[ right click on figure ]]]]]

Matrix dimensions must agree.

Error in ginput2 (line 611)
if all((lim~=zlim))

Timothé Boutelier



To deactivate the rezoom, just comment line 613

% Centers the selected point if ZOOM-IN: 29 SEP,2008
if all((lim~=zlim))
lim = [x+diff(lim(1:2))/2*[-1 1] y+diff(lim(3:4))/2*[-1 1]];
axis(lim) %Comment this line to deactivate recentering after each point selection


needs one big improvement: when I zoom in, the image jumps every time I select a point! this is very annoying... otherwise, a very good tool


Andrew Simpson

This looks very promising, but isn't working for me - I've tried various ways of running it, including the examples in the source, and every time I click on the plot it simply zooms in. I'm sure this isn't the expected behaviour - I can't get it to select any points at all, just zoom.

I'm using R2012a.


Excellent work. Thank you very much.



Thanks for sharing such a useful code,
for my data, after running my code I get images for which I need the following action:
When selecting a part of image,I want Matlab to run my code for that area and calculate or graph other parameters for that part of image,
How can I do that?



I take that back. It does work on 3 dimension picture.
I apologize.

Olga Avila

This is really good!
It works perfect for me, and was exactly what I needed...
I just added a minor detail to plot a line from an input center point to the ginput point selected by the user (like a radial line). This was just to improve visualization for my needs.
Thank you very much!

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

Community Treasure Hunt

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

Start Hunting!