Problem by drawing a line on axes
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Ouael Chkoundali
am 10 Jan. 2019
Kommentiert: Adam Danz
am 10 Jan. 2019
Hallo,
I want to draw a vertical line on an axes on GUI after selecting a point through which the line passes using a callback button.
I have 2 Problems:
1- I can choose a point that is outside the axes.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/200546/image.png)
2- After clicking with the mouse to choose the point, the drawn line doesn't pass through the point and it is not vertical.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/200547/image.png)
Here is my code:
% --- Executes on button press in draw.
function draw_Callback(hObject, eventdata, handles)
% hObject handle to draw (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%h = imline(gca);
axes(handles.axes)
[x,y] = ginput(1);
h = line ([x,y], ylim);
0 Kommentare
Akzeptierte Antwort
Adam Danz
am 10 Jan. 2019
Bearbeitet: Adam Danz
am 10 Jan. 2019
There are two errors.
First, you're getting a diagonal line because the first input of line() contains all x-values but you're entering [x,y].
Second, there's no need to use the y-coodinate of the ginput().
Here's what you want:
line([x,x], ylim)
In addition to this, I suggest using the asix handle to ylim in case a different axis is current.
line([x,x], ylim(h)) %h is the handle to your gui axis.
2 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Graphics Object Programming finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!