4

Matlabの図をクリックして、クリックした位置のxとyの位置を確認したいと思います。

グラフでは、線上の点をクリックして、そのx座標とy座標を取得する方法があると思います。グラフがプロットされていない場合、どうすれば同じことができますか?

4

4 に答える 4

7

これを最もエレガントに行う方法は次のとおりです。

function test

    % create test figure
    f = figure(1);

    % set function to call on mouse click
    set(f, 'WindowButtonDownFcn', @clicker);


end

% function called on mouse click in the figure
function clicker(h,~)


    get(h, 'selectiontype')
    % 'normal' for left moue button
    % 'alt' for right mouse button
    % 'extend' for middle mouse button
    % 'open' on double click

    get(h, 'currentpoint')
    % Current mouse location, in pixels from the lower left.
    % When the units of the figure are 'normalized', the
    % coordinates will be [0 0] inb lower left, and [1 1] in
    % the upper right.

end
于 2012-11-24T08:14:08.187 に答える
6

Figure を作成したら、試してみてください

[x_coord, y_coord]=ginput(1);

そのため、Figure を 1 回クリックするだけで (引数が 1 である理由です)、関数ginput()によって返される座標を取得できます。

于 2012-11-23T13:40:00.950 に答える
1

多分これもうまくいくでしょう:

function [loc] = get_image_point (I)
    figure('name','Doubleclick to set location');imshow(I);
    [c r] = getpts(1);
    loc = int32([c r]);
    if size(loc,1)>1
        loc = [loc(1,1) loc(1,2)];
    end
    close all;
end

ステファン

于 2016-08-10T12:19:10.563 に答える
0

注: - getpts()- は「Image Processing Toolbox」機能です。- ginput()- マウスのクリックを待ち、クリックするまで実行を停止し、呼び出されたときにのみ機能します。

一方get(h, 'currentpoint')、プログラムが実行されている限り、いつでも機能します。

于 2016-12-11T07:27:46.787 に答える