グラフ上の座標の取得

25 Ansichten (letzte 30 Tage)
Mamoru Mabuchi
Mamoru Mabuchi am 16 Jun. 2020
Kommentiert: Mamoru Mabuchi am 21 Jun. 2020
グラフ上の座標を取得する関数ginputは、マウスの左ボタンを押した時の座標しか取得できません。
グラフ上の座標において、マウスの左ボタンを押した時と、左ボタンを放した時両方の座標を取得する方法はありますか?

Akzeptierte Antwort

Akira Agata
Akira Agata am 19 Jun. 2020
figureのコールバック関数 (WindowButtonDownFcn, WindowButtonUpFcn) を使うというのは、いかがでしょうか?
たとえば以下のようにすると、マウスの左ボタンを押した時と解放した時の座標を、それぞれ取得することができます。
figure(...
'WindowButtonDownFcn', @getMousePosition,...
'WindowButtonUpFcn', @getMousePosition)
plot(magic(4))
function getMousePosition(~,event)
ax = gca;
x = ax.CurrentPoint(1,1);
y = ax.CurrentPoint(1,2);
fprintf('%s\t: (x,y) = (%f,%f)\n',event.EventName,x,y);
end
上記を実行して表示されるプロット上で、マウスの左ボタンをクリック ⇒ ドラッグ ⇒ 解放とすると、以下のようにクリック時と解放時の座標がコマンドウィンドウに表示されます。
WindowMousePress : (x,y) = (1.616022,12.878505)
WindowMouseRelease : (x,y) = (2.649171,5.252336)
  1 Kommentar
Mamoru Mabuchi
Mamoru Mabuchi am 21 Jun. 2020
解決しました。
ありごとうございました。

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu グラフィックス オブジェクトのプロパティ finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!