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

2 次查看(过去 30 天)
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:

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Annotations 的更多信息

标签

产品


版本

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by