How can I get the data selected by the user with the datacursor in a Gui?
Ältere Kommentare anzeigen
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.
Akzeptierte Antwort
Weitere Antworten (2)
Aurelien Queffurust
am 2 Mär. 2011
0 Stimmen
Have you tried the ButtonDownFcn callback?
7 Kommentare
Fernando
am 2 Mär. 2011
Paulo Silva
am 2 Mär. 2011
it isn't that simple
Fernando
am 2 Mär. 2011
Oleg Komarov
am 2 Mär. 2011
Then try Paulo's or my solution below.
Paulo Silva
am 2 Mär. 2011
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
am 2 Mär. 2011
The solution I proposed gets just the point clicked.
Fernando
am 2 Mär. 2011
Paulo Silva
am 2 Mär. 2011
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
Kategorien
Mehr zu Graphics Object Properties finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!