MATLABのツリープロットの類似のプロットで、各行のツールチップを作成します。私はプロットの複数の行を必要とする私の更なるプロジェクトでMATLAB:WindowButtonMotionFcnを使用してプロット内の複数の線オブジェクトのツールチップを作成
function test_mouseover2
f=figure(1);
axis([0 1 0 1]);
L=line([0.2500 0.5000], [0.6 0.8], 'Color','red');
set(f,'WindowButtonMotionFcn',{@mousemove,L,process});
end
function mousemove(src,ev,L,process)
obj = hittest(src);
if obj == L
disp('Yes');
else
disp('No');
end
end
:私はマウスがラインオブジェクト上にあるかどうかを示し、次のスクリプトを作成するコード例を使用していました。以下の簡単な例は、2本の線がプロットされていることを示しています。ただし、コマンドウィンドウに結果が「No」常にある:マウスがラインオブジェクト上にあるかどうかを確認するための別のアプローチは、
function test_mouseover2
f=figure(1);
axis([0 1 0 1]);
L=line([0.2500 0.5000; 0.125 0.25], [0.6 0.8; 0.2 0.6], 'Color','red');
set(f,'WindowButtonMotionFcn',{@mousemove,L,process});
end
function mousemove(src,ev,L,process)
obj = hittest(src);
if obj == L
disp('Yes');
else
disp('No');
end
end
ありますか?
ありがとうございます。 'obj'にマッチする' L'要素を得ることが可能かどうか知っていますか? – stm
@stm 'find(obj == L)'は一致するインデックス(または一致しない場合は空の行列)を返します – zeeMonkeez
うわー、それは簡単です...もう一度あなたの助けに感謝します! – stm