Help with graphical input on a GUI axes
조회 수: 2 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
채택된 답변
Walter Roberson
2018년 4월 10일
You can use a loop of ginput(1). Or you can use an axes ButtonDownFcn callback.
추가 답변 (1개)
Tamir Suliman
2018년 4월 10일
I think you may need to implement some while loop or logic to read the cursor location when is changed
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Exploration에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!