This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.


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


MATLAB® returns errors such as the following if you start MATLAB with the –noFigureWindows or –nodisplay flag and then run ginput:

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 =

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.


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.

Introduced before R2006a