Editor's Note: This file was selected as MATLAB Central Pick of the Week
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);
Cite As
Jiro Doke (2024). Custom GINPUT (https://www.mathworks.com/matlabcentral/fileexchange/38703-custom-ginput), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Platform Compatibility
Windows macOS LinuxCategories
Tags
Acknowledgements
Inspired: gdist, clickz, GINPUT FOR UIAXES, gdistm
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.