Select a line object using the mouse

Is there a way to allow the user to select a line object using the mouse and return the handle to the line?

回答 (2 件)

Oleg Komarov
Oleg Komarov 2011 年 3 月 14 日

0 投票

Yes, use the ButtonDownFcn to set a function which retrieves the value of the handle and throws it into the workspace with evalin or putvar (on FEX)
Oleg
Matt Fig
Matt Fig 2011 年 3 月 14 日

0 投票

If you are looking for a quick and dirty way to get the handle from a click, you can do this:
x = 0:.001:1;
L = plot(x,x.^2,x,x.^3,x,x.^4);
set(L,'ButtonDownFcn','Handle = gcbo'); % Now click on a line...
Now if you want to be able to select multiple objects and have the handles stored, or perform manipulations on the lines, you will have to get more sophisticated and do something like what Oleg recommends.

カテゴリ

ヘルプ センター および File ExchangeProgramming Utilities についてさらに検索

質問済み:

2011 年 3 月 14 日

Community Treasure Hunt

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

Start Hunting!

Translated by