Help with graphical input on a GUI axes

3 visualizaciones (últimos 30 días)
HpW
HpW el 10 de Abr. de 2018
Comentada: HpW el 13 de Abr. de 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

Respuesta aceptada

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

Iniciar sesión para comentar.

Más respuestas (1)

Tamir Suliman
Tamir Suliman el 10 de Abr. de 2018
I think you may need to implement some while loop or logic to read the cursor location when is changed

Categorías

Más información sobre Data Exploration en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by