Effacer les filtres
Effacer les filtres

Why is matlab creating multiple figures

49 vues (au cours des 30 derniers jours)
Venessa
Venessa le 7 Août 2024 à 3:09
Réponse apportée : Arjun le 7 Août 2024 à 6:11
I have a picture of the code and part of what its doing when I run it but it is creating hundreds of figures of the two plots I'm trying to create. Clearly I'm missing something
  1 commentaire
KSSV
KSSV le 7 Août 2024 à 3:12
Every time a new figure is being opened becuase figure is mentioned. Comment it or delete this. If you want all plots in a single figure use hold on

Connectez-vous pour commenter.

Réponses (2)

Walter Roberson
Walter Roberson le 7 Août 2024 à 5:06
You are calling figure() within your while loop, so each time you create a new figure.
You should probably be calling figure() passing in a figure number
figure(2);
and
figure(3);

Arjun
Arjun le 7 Août 2024 à 6:11
Hi,
As per my understanding of the question, the issue is that on running the program many figure windows open which is not the desired output.
  • The reason is the abuse of the MATLAB figure inside the while loop which is running N number of times.
  • Each time inside the loop two new figure window are created and thus you get 2*N number of figure windows from inside the while loop itself.
  • Whenever you write figure MATLAB creates a new figure window and automatically sets it as the current window where all the activity will go in.
Please refer more about figure in the documentation attached.
Instead, what you can do is to use figure(x) syntax to select a particular already existing figure and make it current figure and then use hold on to draw in the same plot and same figure.
Please read through documentation of hold.
I hope this will help!

Catégories

En savoir plus sur Graphics Performance dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by