Graphical input from mouse or cursor
[x,y] = ginput(n)
[x,y] = ginput
[x,y,button] = ginput(...)
ginput raises crosshairs in the current axes to for you to identify points in the figure, positioning the cursor with the mouse. The figure must have focus before ginput can receive input. If it has no axes, one is created upon the first click or keypress.
[x,y] = ginput(n) enables you to identify n points from the current axes and returns their x- and y-coordinates in the x and y column vectors. Press the Return key to terminate the input before entering n points. Specify n as a positive integer.
[x,y,button] = ginput(...) returns the x-coordinates, the y-coordinates, and the button or key designation. button is a vector of integers indicating which mouse buttons you pressed (1 for left, 2 for middle, 3 for right), or ASCII numbers indicating which keys on the keyboard you pressed.
Clicking an axes makes that axes the current axes. Even if you set the current axes before calling ginput, whichever axes you click becomes the current axes and ginput returns points relative to that axes. If you select points from multiple axes, the results returned are relative to the coordinate system of the axes they come from.
Coordinates returned by ginput are scaled to the XLim and YLim bounds of the axes you click (data units). Setting the axes or figure Units property has no effect on the output from ginput. You can click anywhere within the figure canvas to obtain coordinates. If you click outside the axes limits, ginput extrapolates coordinate values so they are still relative to the axes origin.
The figure CurrentPoint property, by contrast, is always returned in figure Units, irrespective of axes Units or limits.
Pick 4 two-dimensional points from the figure window.
[x,y] = ginput(4)
Position the cursor with the mouse. Enter data points by pressing a mouse button or a key on the keyboard. To terminate input before entering 4 points, press the Return key.
x = 0.2362 0.5749 0.5680 0.2707 y = 0.6711 0.6769 0.4313 0.4401 plot(x,y)
In this example, plot rescaled the axes x-limits and y-limits from [0 1] and [0 1] to [0.20 0.65] and [0.40 0.75]. The rescaling occurred because the axes XLimMode and YLimMode are set to 'auto' (the default). Consider setting XLimMode and YLimMode to 'manual' if you want to maintain consistency when you gather results from ginput and plot them together.