How to plot the second point of line at mouse location

조회 수: 5 (최근 30일)
Dominik Mattioli
Dominik Mattioli 2018년 7월 31일
댓글: Dominik Mattioli 2018년 8월 1일
I'd like to plot a line defined by two points, one that is already selected in [x,y] space, and the other that is unselected, but previewed by plotting the second point at the current position of the mouse (get(h,'CurrentPoint')).
Additionally, a plot object shows the resulting line between these two points as the cursor moves in the window.
The second point is selected with a mouse click.
  댓글 수: 2
Greg
Greg 2018년 8월 1일
What have you tried so far? Where specifically are you stuck?
Dominik Mattioli
Dominik Mattioli 2018년 8월 1일
I'm trying to learn about the ButtonDownFcn, WindowButtonMotionFcn, and the other mouse callbacks. I don't think the documentation has any examples and it seems like you just need to "figure it out" on your own somehow, so I'm asking this question as an example problem.

댓글을 달려면 로그인하십시오.

답변 (1개)

KSSV
KSSV 2018년 8월 1일
P = rand(1,2) ;
figure
axis([-1 1 -1 1])
hold on
plot(P(1,1),P(1,2),'.r')
pts = zeros([],2) ;
for i = 1:10
[px,py] = getpts() ;
pts(i,:) = [px py] ;
plot(px,py,'.b') ;
plot([P(1,1) pts(i,1)],[P(1,2) pts(i,2)],'r')
drawnow
end
double click , at a desired point when figure is opened.
  댓글 수: 1
Dominik Mattioli
Dominik Mattioli 2018년 8월 1일
This is nice and very close to what I'm trying to do. I'm curious if you know how to make the plot update the second point as you move your cursor? Very similar to the imline function.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Graphics Object Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by