get on click coordinates from a plot (multiple times)

조회 수: 84 (최근 30일)
Max Müller
Max Müller 2014년 9월 10일
댓글: Max Müller 2014년 9월 11일
Heyho,
the function [x,y]= ginput (n) gives back the x and y data of the curse position while clicking. The Problem: I want to give the user the possibility to click multiple times in a row. However, I need the click to have a direct effect.
So if n>1 the function waits for n clicks to be done before returning the x/y Data.I want to click --> get Values --> click --> get values --> click on the button --> finish. My idea was to use a Pushbutton which sets the ginput into an eternal loop, which can be broken be clicking agian.
function CollectePointsButton_Callback(hObject, eventdata, handles)
Counter = getappdata(hObject,'Counter');
if isempty(Counter) == 1;
Counter = 0;
end
Data = findobj('type','axes');
set(Data,'buttondownfcn',@ClickToCollecte);
Counter = Counter +1;
setappdata(handles.CollectePointsButton,'Counter',Counter);
function ClickToCollecte (gcbo,evendata,handles)
Data = findobj('tag','CollectePointsButton');
Counter = getappdata(Data,'Counter')
while mod(Counter,2) == 1
Data = findobj('tag','CollectePointsButton');
Counter = getappdata(Data,'Counter')
[x,y] = ginput(1);
end

채택된 답변

Mischa Kim
Mischa Kim 2014년 9월 10일
Hello Max, check out this answer.
It uses left-mouse clicks to collect data and a right-mouse click to finish collecting data.
  댓글 수: 3
Mischa Kim
Mischa Kim 2014년 9월 11일
ginput reads position values as long as you keep using the left-mouse button ( button = 1 ). As soon as you use the right-mouse button, button = 3, and the loop is exited.
Max Müller
Max Müller 2014년 9월 11일
cool thanks

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by