How can I get the data selected by the user with the datacursor in a Gui?
이전 댓글 표시
I have been tryng to create a gui where a user selects a point in a graph. I want to get the user selection to run another function later. I tried to create a function callback in the points in the graph but did not work. How do I create a callback to the graph points?
Thanks.
채택된 답변
추가 답변 (2개)
Aurelien Queffurust
2011년 3월 2일
0 개 추천
Have you tried the ButtonDownFcn callback?
댓글 수: 7
Fernando
2011년 3월 2일
Paulo Silva
2011년 3월 2일
it isn't that simple
Fernando
2011년 3월 2일
Oleg Komarov
2011년 3월 2일
Then try Paulo's or my solution below.
Paulo Silva
2011년 3월 2일
My solution doesn't use the datacursor, it just gets the current point when the user clicks on the figure, that was because the datacursor function implements it's own callbacks, I would suggest some alterations to the datacursormode function (make a custom one) but it's not easy.
Maybe adding the detection of the return key or space key in the code
% Parse key press
movedir = [];
switch keypressed
case 'leftarrow'
movedir = 'left';
case 'rightarrow'
movedir = 'right';
case 'uparrow'
movedir = 'up';
case 'downarrow'
movedir = 'down';
case 'alt'
consumekey = true;
end
Make it do something else when those keys are detected but it might not be easy.
I recall that something similar was already discussed and Jiro proposed a solution here on answers, I think I have the code somewhere in my laptop :s
Oleg Komarov
2011년 3월 2일
The solution I proposed gets just the point clicked.
Fernando
2011년 3월 2일
Paulo Silva
2011년 3월 2일
function testbdown
fig=figure;
ax=axes;
set(ax,'ButtonDownFcn',@detbut);
function detbut(a,b)
cp=get(a,'CurrentPoint');
x=cp(1,1)
y=cp(1,2)
%comment the next line if you want to keep getting x,y for more points
set(ax,'ButtonDownFcn','');
%hold on %in case you want to keep several points marked on the axes
%plot(x,y,'x') %in case you want to mark the points
end
end
카테고리
도움말 센터 및 File Exchange에서 Graphics Object Properties에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!