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

2 views (last 30 days)
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.

Accepted Answer

Zinea
Zinea on 10 Oct 2024
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 Comment
Graham
Graham on 11 Oct 2024
I have used your proposed solution successfully. Thank-you very much for your help.

Sign in to comment.

More Answers (0)

Tags

Products


Release

R2024b

Community Treasure Hunt

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

Start Hunting!