필터 지우기
필터 지우기

Problem by drawing a line on axes

조회 수: 1 (최근 30일)
Ouael Chkoundali
Ouael Chkoundali 2019년 1월 10일
댓글: Adam Danz 2019년 1월 10일
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.
2- After clicking with the mouse to choose the point, the drawn line doesn't pass through the point and it is not vertical.
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);

채택된 답변

Adam Danz
Adam Danz 2019년 1월 10일
편집: Adam Danz 2019년 1월 10일
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
Ouael Chkoundali
Ouael Chkoundali 2019년 1월 10일
Thanks a lot Adam
Adam Danz
Adam Danz 2019년 1월 10일
Glad it all worked out!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Graphics Object Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by