How to create a program that creates an axes object and that plots a line connecting the locations of successive mouse clicks within the axes. Using the waitforbuttonpress function to wait for mouse clicks and update the plot after each click. Terminate the plot when a keyboard press occurs.

 채택된 답변

Ameer Hamza
Ameer Hamza 2020년 4월 19일
편집: Ameer Hamza 2020년 4월 19일

1 개 추천

Run this example
f = figure(); % create figure and get its handle
ax = axes(); % create axes and get its handle
xlim([0 1]); % set limits of axes
ylim([0 1]);
hold on; % hold the axes so that the xlim and ylim does not change.
l = line(0, 0); % create an empty line
l.XData = [];
l.YData = [];
while waitforbuttonpress == 0
point = ax.CurrentPoint(1, 1:2); % get coordinate of current point
l.XData = [l.XData point(1)]; % add the current point to the line l
l.YData = [l.YData point(2)];
end

댓글 수: 2

Saurav Karmakar
Saurav Karmakar 2020년 4월 19일
Can you explain the steps @Ameer Hamza?
Ameer Hamza
Ameer Hamza 2020년 4월 19일
Saurav, I have added comments with the code.

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Graphics Object Properties에 대해 자세히 알아보기

제품

릴리스

R2015b

질문:

2020년 4월 19일

댓글:

2020년 4월 19일

Community Treasure Hunt

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

Start Hunting!

Translated by