Help with graphical input on a GUI axes

2 vues (au cours des 30 derniers jours)
HpW
HpW le 10 Avr 2018
Commenté : HpW le 13 Avr 2018
Hi. I have a simple GUI where a signal is loaded from a file, and then displayed in a GUI axes. I want to let the user click somewhere on the signal, get the x coordinate, and then draw a vertical line at this point. I have been trying to do this using the following code, but it has some issues:
% load signal....
axes(handles.signal_axis);
plot(signal)
hold on
dcm_obj = datacursormode;
set(dcm_obj,'DisplayStyle','datatip',...
'SnapToDataVertex','off','Enable','on')
% Select x coordinate where click on plot
waitforbuttonpress;
c_info = getCursorInfo(dcm_obj);
x = c_info.DataIndex
% draw line at x coordinate
line([x x], [ min(ylim) max(ylim) ], 'color', 'r', 'linewidth',3,'LineStyle',':')
hold off
The issues with this are: 1. once the user clicks on the signal to get the data index (x value), if they click again it does not work since ive exited the waitforbuttonpress section of code. I therefore have to reload the entire signal to choose another x value/draw another line in a new location.
2. If i click anywhere other than on the actual signal, I get an error.
Can someone please help me with this? Id ideally like to be able to click multiple times on the axes displaying the signal and each time it should allow me to get the data index and draw a line there.
Also, is there a way to do this just by clicking somewhere in the axes object rather than having to click exactly on the plotted signal?
thanks for the help!!
h

Réponse acceptée

Walter Roberson
Walter Roberson le 10 Avr 2018
You can use a loop of ginput(1). Or you can use an axes ButtonDownFcn callback.
  1 commentaire
HpW
HpW le 13 Avr 2018
thanks!! Did ginput(1) with ButtonDownFcn - works great!

Connectez-vous pour commenter.

Plus de réponses (1)

Tamir Suliman
Tamir Suliman le 10 Avr 2018
I think you may need to implement some while loop or logic to read the cursor location when is changed

Catégories

En savoir plus sur Data Exploration dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by