Code covered by the BSD License  

Highlights from
Custom GINPUT

5.0

5.0 | 6 ratings Rate this file 55 Downloads (last 30 days) File Size: 4.56 KB File ID: #38703
image thumbnail

Custom GINPUT

by

 

GINPUT with customizable cursor.

Editor's Notes:

This file was selected as MATLAB Central Pick of the Week

| Watch this File

File Information
Description

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);

Acknowledgements

This file inspired Gdistm and Gdist.

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 (11)
12 Sep 2014 adi

just great!

28 Jul 2014 arnold

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

28 Jul 2014 arnold

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

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.

24 Jan 2013 Wolfgang Schwanghart

Jiro, thanks for the quick reply and fix!

23 Jan 2013 Anon

Thanks!

23 Jan 2013 Jiro Doke

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

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?

28 Nov 2012 Jiro Doke

@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?

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

13 Nov 2012 Stefano

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

Contact us