문제

나는 모든 곳에서 찾고 있었지만 이것을하는 방법을 보여주는 사이트를 찾을 수는 없습니다. 내가 원하는 것은 그것을 클릭 할 때 축에서 물체를 선택할 수 있어야합니다. 그래서 색상과 물건을 변경할 수 있습니다.

아이를 선택하는 방법을 알아낼 수는 없지만 객체를 만들 수는 있지만 선택하지는 않습니다.

라인을 만드는 데 사용하는 코드가 있습니다.

coord = ginput (2)
x = coord(:,1)
y = coord(:,2)
hline = line(x,y)
.

배열에 개체를 만들어 편집 / 삭제를 선택할 수 있는지 모르겠습니다. 나는 buttondownfcn을 사용해야 할 필요가 있다고 믿지만, 아마도 내가 무언가를 완전히 틀리게하고 있습니다.

아무 도움이 될 것입니다. 정보가 누락되면 알려주세요

감사합니다

도움이 되었습니까?

해결책

It is not necessary to use ginput and extract the coordinates. This is done automatically by an built-in "listener" in the figure-window. You are correct in assuming that you can use the ButtonDownFcn property on the object (line, lineseries, or other handle graphics object).

Try to create at simple line from (0,0) to (1,1):

hline = line([0,1],[0,1]) %# create line, save handle in hline

Then you can set the ButtonDownFcn to, for instance, a function handle to an anonymous function:

set( ...
   hline, ...
   'ButtonDownFcn', @(handle,event)(disp(['You clicked on the line!'])) ...
);

Now try to click on the line. It should print the text in the command window.

The function needs to be able to receive atleast two arguments: (1) the handle of the object itself (the line) and (2) an "event structure". I believe the second argument is just empty when you use line-objects. But your function still needs to receive atleast these two arguments (even if you do not use them).

Read more here: http://www.mathworks.com/help/techdoc/ref/line_props.html.

You can also use your own function (a named function in a file):

set( ...
   hline, ...
   'ButtonDownFcn', @(handle,event)(namedFunction(handle,event)) ...
);

... or you can use a struct-array if you (expectedly) have other arguments beyound those two.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top