View License

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

» Watch video

Highlights from

4.7 | 12 ratings Rate this file 49 Downloads (last 30 days) File Size: 4.56 KB File ID: #38703 Version:



Jiro Doke (view profile)


07 Nov 2012 (Updated )

GINPUT with customizable cursor.

| Watch this File

File Information

This function behaves similarly to MATLAB's GINPUT, with an added ability to customize the cursor color, line width, and line style. From the function HELP:
[X,Y] = ginputc(N) gets N points from the current axes and returns the X- and Y-coordinates in length N vectors X and Y. The cursor can be positioned using a mouse. Data points are entered by pressing a mouse button or any key on the keyboard except carriage return, which terminates the input before N points are entered. Note: if there are multiple axes in the figure, use mouse clicks instead of key presses. Key presses may not select the axes where the cursor is.

[X,Y] = ginputc gathers an unlimited number of points until the return key is pressed.

[X,Y] = ginputc(N, PARAM, VALUE) and [X,Y] = ginputc(PARAM, VALUE) specifies additional parameters for customizing. Valid values for PARAM are:
'Color' : A three-element RGB vector, or one of the MATLAB predefined names, specifying the line color. See the ColorSpec reference page for more information on specifying color. Default is 'k' (black).
'LineWidth' : A scalar number specifying the line width. Default is 0.5.
'LineStyle' : '-', '--', '-.', ':'. Default is '-'.
'ShowPoints' : TRUE or FALSE specifying whether to show the points being selected. Default is false.
'ConnectPoints' : TRUE or FALSE specifying whether to connect the points as they are being selected. This only applies when 'ShowPoints' is set to TRUE. Default is true.

[X,Y,BUTTON] = ginputc(...) returns a third result, BUTTON, that contains a vector of integers specifying which mouse button was used (1,2,3 from left) or ASCII numbers if a key on the keyboard was used.

[X,Y,BUTTON,AX] = ginputc(...) returns a fourth result, AX, that contains a vector of axes handles for the data points collected.

 [x, y] = ginputc;

 [x, y] = ginputc(5, 'Color', 'r', 'LineWidth', 3);

 [x, y, button] = ginputc(1, 'LineStyle', ':');

 subplot(1, 2, 1); subplot(1, 2, 2);
 [x, y, button, ax] = ginputc;

 [x, y] = ginputc('ShowPoints', true, 'ConnectPoints', true);


This file inspired Gdistm, Gdist, and Clickz.

Required Products MATLAB
MATLAB release MATLAB 8.0 (R2012b)
Other requirements Requires R2007b or newer.
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (22)
25 Jan 2017 Armindo

Hi Thank you fot this is very nice. I have been unabe to add a scroll properlly to this can you help me on this please. kind regards.

13 Dec 2016 plasmageek

Mathworks, implement this please!!!

23 Nov 2016 Gary Pajer

R2015a, macOS 10.12.1.

This function does not work if I have zoomed in on a portion of my axes, and the zoom icon (GUI figure toolbar) is active. If I first de-select the zoom icon, it works. ginput() works with zoom selected, ginputc() does not.

If I forget to de-select the zoom icon, and click in my axes, nothing seems to happen. But if I then de-select zoom, the GUI gets confused. *Other* axes do not draw, and there is a crosshair frozen in the upper left of the GUI, plus another movable crosshair that, does nothing on the first use, but works properly on the second use. The frozen crosshair appears to be "permanent".

Comment only
31 Mar 2016 Reza

Reza (view profile)

Thanks for the program. I found out that it doesn't show properly the values smaller than 0.0001. Can you let me know how can I fix it.

Comment only
12 Mar 2016 Devraj Mandal

It is very good.

10 Mar 2016 Sam

Sam (view profile)

05 Jul 2015 Michel bertrand

This looks like nice piece of work; I just used it for a few hours testing the program I am developing now, but I will definitely try it later on other codes to see how it goes instead of ginput
One thing I liked, is that I could easily modify ginputc so it also records key modifier (alt,control,shift pressed while clicking); I have been waiting for this for a long time until I saw ginputc.
I also observed a rather slow cursor (compared to ginput), and in my case the solution suggested by Nathanael Berglund is not improving this. ( not so surprising since I do not not have so many plot objets)
I am using ginputc in a program run on a remote computer (through remote desktop) which obviously slows down cursor movement; but it is nevertheless uncomfortably slower than ginput in the same situation. Any idea how to improve cursor speed; I could check with the profiler, though I never used the profiler for improving event driven code.

18 Jun 2015 azzam mahmood

thanks for the great tool, but i facing this massage when i tried to use this function
warning: "Warning: Text handle output is not supported for managed labels. "
error: "Error while evaluating uicontrol Callback"

10 Jun 2015 Markus Roßmann

If I use Matlab 2014a this function doesn't work but with Matlab 2011 it works great.
At Matlab 2014a the couror is always behind the panel. That is not usable because you can not see where you click.

Is there a solution available?

Comment only
25 May 2015 arnold

arnold (view profile)

is there a way to move the cursor using the cursor keys on the keyboard? I think this would be great since it could be more accurate.

My cursor is quite slow using this function, moves around with maybe 5-10 frames per second.

Comment only
26 Jan 2015 Nathanael Berglund

One thing I have noticed. If I am using this on a figure that has a large number of plot objects, the call to isprop can be very slow, so I added a line to exclude the objects plotted to the current axis from consideration when setting the event handler properties.

allHG = findall(hFig);

I added:
allHG = allHG(cellfun(@(x) hAx~=x, get(allHG,'Parent'))); % Exclude graphics objects that are children of the current axis

which sped things up quite a bit for my graphics-heavy plot.

Comment only
12 Sep 2014 adi

adi (view profile)

just great!

28 Jul 2014 arnold

arnold (view profile)

I was too quick with that question. Found the included function for removing points via delete/backspace. Many thanks!

28 Jul 2014 arnold

arnold (view profile)

it would be great if one could define a key or mousebutton (like right click) to remove the last point!

10 Mar 2014 John L

John L (view profile)

Jiro, thanks for the great tool. Is it possible to make it so that the cross-hair is a specified size (i.e. limit the size to a cm or two)? When I use it, it goes across the page outside the panel.

Comment only
24 Jan 2013 Wolfgang Schwanghart

Jiro, thanks for the quick reply and fix!

23 Jan 2013 Anon

Anon (view profile)


23 Jan 2013 Jiro Doke

Jiro Doke (view profile)


Thanks for pointing this out. It was a bug. I'll fix it and resubmit. In the meantime, please replace the following lines in my code:

addParamValue(p, 'LineStyle', '-' , @(x) validatestring(x, ...
{'-', '--', '-.', ':'}));


addParamValue(p, 'LineStyle', '-' , @(x) ischar(validatestring(x, ...
{'-', '--', '-.', ':'})));

Comment only
23 Jan 2013 Wolfgang Schwanghart

Great tool! Yet, there seems to be a bug which I cannot resolve. I called ginputc with

[x,y,button] = ginputc(1,'color','r','LineStyle','--')

in a function mytool. Despite the LineStyle should be valid, I receive following error message.

Error using mytool>ginputc (line 135)
Argument 'LineStyle' failed validation @(x)validatestring(x,{'-','--','-.',':'}).
Error in mytool (line 29)
[x,y,button] = ginputc(1,'color','r','LineStyle','--');

Any ideas?

Comment only
28 Nov 2012 Jiro Doke

Jiro Doke (view profile)


Can you elaborate a little bit more? Are you saying that you want to pass a "list" of x-y coordinates, so that the additional points you click will be appended to the list? Or are you saying that you want to pass a pair of x-y coordinates and the cursor to be initially placed at that coordinate?

Comment only
13 Nov 2012 Stefano

one thing: it would be nice to call the function with already a list of [x,y] coordinates. I'm trying to implement it, but it doesn't work properly yet...

Comment only
13 Nov 2012 Stefano

Great function. Exact what I needed.
And with a clear code too :)

01 Sep 2016

Updated license

Contact us