MATLAB-ginput函数问题

functions:Graphical input from mouse or cursor

ginput提供了一个十字光标使我们能更精确的选择我们所需要的位置,并返回坐标值。函数调用形式为:

[x,y] = ginput(n)
[x,y] = ginput
[x,y,button] = ginput(...)

对于[x,y] = 
ginput(n),能使你从当前的坐标系中读取n个点,并返回这n个点的x,y坐标,均为nX1的向量。可以按回车提前结束读数。

[x,y] = ginput 可以无限的读取坐标直到按下回车键。

[x,y,button] = ginput(...) 
返回x和y的坐标,以及button值(1=左键,2=中,3=右)或者按键的ASXII码值。

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.

example:

>> [x,y,button] = ginput(1)

x =

    0.1118

y =

    0.6623

button =

     1

button返回次数,x,y分别返回的是鼠标所点的坐标。

Matlab获取鼠标坐标值的ginput()函数

获取鼠标坐标值的第一种途径:利用Matlab7.0 中

figure的WindowButtonDownFcn属性。当你在图上按下鼠标的时候,可通过该属性定义一个回调程序。回调程序可以是一个有效的Matlab表达式或者一个M文件。

那么为显示当前鼠标按下时的坐标值,我们可以将其定义为一个坐标获取和显示程序。

例如:

% 主函数

function test_mouse_track()
figure;
axis([-10,10,0,5]);
set(gcf,'WindowButtonDownFcn',@ButttonDownFcn);

% 回调函数

function ButttonDownFcn(src,event)
pt = get(gca,'CurrentPoint');
x = pt(1,1);
y = pt(1,2);
fprintf('x=%f,y=%fn',x,y);Matlab的ginput()函数

获取鼠标坐标值的第二种途径:

ginput提供了一个十字光标使我们能更精确的选择我们所需要的位置,并返回坐标值。函数调用形式为:

[x,y] = ginput(n)
[x,y] = ginput
[x,y,button] = ginput(...)

对于[x,y] = ginput(n),能使你从当前的坐标系中读取n个点,并返回这n个点的x,y坐标,均为nX1的向量。可以按回车提前结束读数。

[x,y] = ginput 可以无限的读取坐标直到按下回车键。

[x,y,button] = ginput(...) 返回x和y的坐标,以及button值(1=左键,2=中,3=右)或者按键的ASXII码值。

原文地址:https://www.cnblogs.com/lihuidashen/p/3443435.html