Problem with plotting + on a figure using the plot function.

조회 수: 7 (최근 30일)
Graham
Graham 2024년 10월 10일
댓글: Graham 2024년 10월 11일
The short program plot_test reads in the .jpg file Scope_2-Scale_50X.jpg. This .jpg file is a scaling file for an image analysis program the short program plot_test is part of. The .jpg file Strange shows how it doesn't matter where I click on the image, the red '+' is placed in a straight line. The x-coordinate fits with the point at which I click on the image but the y-coordinate does not. I am at a loss to understand why the plot function does not place the red '+' where I click on the image.

채택된 답변

Zinea
Zinea 2024년 10월 10일
The behavior above is occurring due to how the coordinates are being extracted and plotted. In MATLAB, when you use get(gca, 'CurrentPoint'), it returns a 2x3 matrix, where each row is a point in the form [x, y, z]. The first row corresponds to the point in the axes plane, which is what you want for 2D plotting.
To resolve the issue, you should add the following lines after waitforbuttonpress. This ensures you are using the correct values from the matrix returned by get.
x = scale_start(1, 1);
y = scale_start(1, 2);
Also, plot the point using the correct x, y after hold on.
plot(x, y, '+r');
Here is a screenshot with the 'red +' being marked at the exact point where clicked and not just on a straight line:
  댓글 수: 1
Graham
Graham 2024년 10월 11일
I have used your proposed solution successfully. Thank-you very much for your help.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

태그

제품


릴리스

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by