Borrar filtros
Borrar filtros

bugs about rectangle and hold in MATLAB R2020a

1 visualización (últimos 30 días)
Tony Liu
Tony Liu el 9 de Mayo de 2020
Comentada: Tony Liu el 21 de Jun. de 2020
Recently I met a strange situation in MATLAB R2020a. To simplify the problem, I write an example script.
rectangle('Position',rand(1,4));
hold on;
plot(rand(),rand(),'o')
hold off;
Then, run the script for many times.
In MATLAB R2017a, the scipt plot a random rectangle and a random point each time you run the script, as expected.
But in MATLAB R2020a, the script add a random rectangle and a random point to the plot each time you run the script, as if the 'hold off' is uesless!
The problem is gone when I change the 'rectangle' function to another 'plot' function. So I think this may be a bug about 'rectangle' and 'hold' in R2020a.

Respuesta aceptada

Tanisha Gosain
Tanisha Gosain el 19 de Jun. de 2020
This behaviour is expected and correct. I also tried reproducing your code in R2017a and got the same results as R2020a.
The rectangle function plots into the current axes without clearing existing content from the axes. Please refer to the description subsection in the documentation of rectangle function: rectangle documentation.
To open a separate plot every time you run your code you can do this:
close all;
rectangle('Position',rand(1,4));
hold on;
plot(rand(),rand(),'o')
hold off;
  1 comentario
Tony Liu
Tony Liu el 21 de Jun. de 2020
You solved my problems at all! I will read the documentation carefully the next time. My sincere gratitude.

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Productos


Versión

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by