버전 (11.8 KB) 작성자: Chad Greene
Get distances between points from mouse clicks on a figure.
다운로드 수: 413
업데이트 날짜: 2014/11/20

라이선스 보기

gdist returns the graphical distance between click points from mouse. This function is a modified form of ginput, but differs in that gdist can return distance between each point or cumulative distance along a path of clicked points. gdist gives the user visual confirmation of clicked points, and points can be undone using the backspace key.
Data points are entered by pressing a mouse button or any key on the keyboard except the following:
Carriage return Terminates data entry.
Backspace Deletes previous data point.
z Zooms in, centered on current cursor location.
x Zooms out, centered on current cursor location.

EuclideanDistance = gdist
PathDist = gdist('path')
[...] = gdist(N)
[...] = gdist('color',ColorSpec)
[...,x,y] = gdist(...)
[...,x,y,h] = gdist(...)

EuclideanDistance = gdist gathers an unlimited number of points until the return key is pressed. Length of EuclideanDistance array is N-1 and is equivalent to EuclideanDistance = diff(PathDist).

PathDist = gdist('path') returns the distance traveled along a path of N clicks. Length of PathDist is equal to the number of clicks N, and the first first value in PathDist will always be zero. PathDist is equivalent to PathDist = [0;cumsum(EuclideanDistance)];

[...] = gdist(N) gets N points from the current axes and returns a vector containing the Euclidean distance from point to point.

[...] = gdist('color',ColorSpec) specifies color of the temporary lines and markers placed on the plot to assist the user.

[...,x,y] = gdist(...) returns x and y coordinates of clicked points.

[...,x,y,h] = gdist(...) returns a handle of line and marker objects clicked by the user. If a handle h is requested, the markers are not automatically removed after the point-entering process has terminated.

Any of the inputs described above can be combined in one argument. For example, after plotting some data like this:


you can simply type


to enter as many points as you'd like via mouse clicks. Or if you know ahead of time that you want to enter 4 points, type


or if you want to calculate the cumulative distance at each step along 4-point path, and you want the temporary guiding lines to be red, type


If you'd like to keep that red line in place after using gdist, request the handle h like this:

[pathdist,~,~,h] = gdist(4,'path','color','red');

Then you can delete the red line at your leisure by


For greater precision, type z to zoom in, or x to zoom out. Zooming in or out recenters the plot on the current mouse position. If you accidentally click a point you'd like to undo, click backspace.

인용 양식

Chad Greene (2024). gdist (, MATLAB Central File Exchange. 검색됨 .

MATLAB 릴리스 호환 정보
개발 환경: R2014b
모든 릴리스와 호환
플랫폼 호환성
Windows macOS Linux
Help CenterMATLAB Answers에서 Visual Exploration에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
버전 게시됨 릴리스 정보

fixed automatic naming.

Now supports line colorspec and zooming.

fixed automatic naming.

Now allows user to undo previous click using the backspace key. Also now includes a cumulative path distance option.