Problem with plotting + on a figure using the plot function.
3 views (last 30 days)
Show older comments
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.
0 Comments
Accepted Answer
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:
More Answers (0)
See Also
Categories
Find more on Annotations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!