File Exchange

image thumbnail

Custom GINPUT

version 1.0.0.1 (4.56 KB) by

GINPUT with customizable cursor.

4.71429
17 Ratings

48 Downloads

Updated

View License

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.

Examples:
[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);

Comments and Ratings (27)

exactly what i was looking for

Jiseok Lee

Super useful thanks

Thank you !!!!!

Nik Ritzmann

Nice and handy functionality! I used it to segmentize recorded time signal tracks. Triggering caption of the current coordinate by key press was especially usefull, because it allowed me to encode simple label information into each data point.
While this functionality worked smoothly in Matlab R2014b, I encountered a problem when using it on R2015a: There, each key press resulted in two new points being added with the same coordinate. It seems with R2015a, two key press events get fired upon every single key being hit.

I was able to work around this by replacing line 250 (in version dated 2016-09-01)

if isempty(key)

by

if isempty(key) || nargin >= 2 && ~strcmp(varargin{2}.EventName, 'KeyPress') % NkR170403: Accept only KeyPress

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.

plasmageek

Mathworks, implement this please!!!

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".

Reza

Reza (view profile)

Hi,
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.
Best,
RB

Devraj Mandal

It is very good.

Sam

Sam (view profile)

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.
Thanks

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"

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?

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.

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.

After:
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.

adi

adi (view profile)

just great!

arnold

arnold (view profile)

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

arnold

arnold (view profile)

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

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.

Jiro, thanks for the quick reply and fix!

Anon

Anon (view profile)

Thanks!

Jiro Doke

Jiro Doke (view profile)

@Wolfgang,

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, ...
{'-', '--', '-.', ':'}));

to:

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

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?

Jiro Doke

Jiro Doke (view profile)

@Stefano,

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?

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...

Stefano

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

Updates

1.0.0.1

Updated license

MATLAB Release
MATLAB 8.0 (R2012b)
Acknowledgements

Inspired: gdistm, gdist, clickz

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

» Watch video