Main Content

ginput

确定轴coordinates

Description

example

[x,y] = ginput(n)allows you to identify the coordinates ofnpoints within Cartesian, polar, or geographic axes. To choose a point, move your cursor to the desired location and press either a mouse button or a key on the keyboard. Press theReturnkey to stop before allnpoints are selected. MATLAB®returns the coordinates of your selected points. If there are no axes, callingginputcreates a Cartesian axes object.

example

[x,y] = ginputallows you to select an unlimited number of points until you press theReturnkey.

example

[x,y,button] = ginput(___)also returns the mouse button or key on the keyboard used to select each point.

Examples

collapse all

Identify four points in a set of axes usingginput. To select each point, move the cursor to your desired location and press a mouse button or key.

(x, y) = ginput (4)

x = 0.3699 0.4425 0.5450 0.6130 y = 0.6690 0.5605 0.4719 0.6025

Plot the points.

plot(x,y);

Identify five coordinates in a set of axes usingginput. To select each point, move the cursor to your desired location and press a mouse button, lowercase letter, uppercase letter, number, or the space bar. Return the mouse buttons or ASCII numbers of the keys used to select each point.

[x,y,button] = ginput(5); button
button = 3 104 32 51 82

In this case, the coordinates were identified using the right mouse button (3), the lowercase letterh(104), the space bar (32), the number3(51), and the uppercase letterR(82).

Create geographic axes and identify the latitude and longitude coordinates of four points. Then, plot the points that you identify.

geoaxes [lat,lon] = ginput(4);

Use thehold oncommand and thegeolimitsfunction to maintain the map limits. Plot the identified points.

holdongeolimits(“手动”) geoscatter(lat,lon,'filled','b')

Input Arguments

collapse all

Number of points to identify, specified as a positive integer.

Output Arguments

collapse all

First components of the identified coordinates, returned as a scalar or column vector.

  • For Cartesian axes, the values arex-coordinates.

  • For polar axes, the values are theta angles. The theta angles are in the range[tmin, tmin+2*pi], wheretminis the first value of theThetaLimvector of the polar axes. The angles are measured from the location of the zero angle in the direction specified by theThetaDirproperty. The location of the zero angle is specified by theThetaZeroLocationproperty.

  • For geographic axes, the values are latitudes. Positive values correspond to north and negative values correspond to south.

If you choose points outside the axes limits, the values are relative to the origin for Cartesian and geographic axes. For polar axes, the values are relative to theThetaZeroLocation.

Second components of the identified coordinates, returned as a scalar or column vector.

  • For Cartesian axes , the values arey-coordinates.

  • For polar axes, the values are radii. Each radius value is greater than or equal tormin, whererminis the first value in theRLimvector of the polar axes.

  • For geographic axes, the values are longitudes. Positive values correspond to locations east of the origin and negative values correspond to locations west of the origin.

If you choose points outside the axes limits, values are still returned relative to the axes origin.

Keys or mouse buttons used to identify points, returned as a scalar or column vector. Mouse buttons are indicated by 1 for the left button, 2 for the middle, and 3 for the right. Double-clicks are indicated by two values. The first value is 1 for the left mouse button, 2 for the middle, and 3 for the right. The second value is 1.

Keys on the keyboard are indicated by their corresponding ASCII numbers. Taps on a screen are indicated by 1.

For example, callginput, click using the middle mouse button, double-click using the right mouse button, and then pressEnter. The outputbuttonis a vector containing2,3, and1.

[~,~,button] = ginput
button = 2 3 1

See Also

Functions

Introduced before R2006a