Graphical input from mouse or cursor
[x,y] = ginput(n)
[x,y] = ginput
[x,y,button] = ginput(...)
ginput raises crosshairs in the current axes 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
y column vectors.
Press the Return key to terminate the input before
n points. Specify
a positive integer.
[x,y] = ginput gathers an
unlimited number of points until you press the Return key.
[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
axes you click becomes the current axes and
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.
MATLAB® returns errors such as the following if you start MATLAB with
and then run
Error using ginput (line 31) Terminal mode is no longer supported
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,
the axes x-limits and y-limits
[0 1] and
[0 1] to
[0.40 0.75]. The rescaling
occurred because the axes
'auto' (the default). Consider setting
you want to maintain consistency when you gather results from
plot them together.
Coordinates returned by
ginput are scaled
of the axes you click (data units). Setting the axes or figure
has no effect on the output from
can click anywhere within the figure canvas to obtain coordinates.
If you click outside the axes limits,
coordinate values so they are still relative to the axes origin.