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

3 visualizaciones (últimos 30 días)
Graham
Graham el 10 de Oct. de 2024
Comentada: Graham el 11 de Oct. de 2024
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.

Respuesta aceptada

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

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre MATLAB en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by