Why does MATLAB consume a large amount of memory when using a numeric slider and plotting figures in a live script?
6 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
MathWorks Support Team
le 22 Juin 2023
Modifié(e) : MathWorks Support Team
le 3 Août 2023
I have a live script containing both a numeric slider for a variable and and a "figure" command.
figure;
x= <Numeric Slider>;
plot(x);
Every time the value of "x" changes, the section is re-run and more hidden figures get generated which cause MATLAB to consume a large amount of memory.
Is this expected behavior and how can I resolve this issue?
Réponse acceptée
MathWorks Support Team
le 2 Août 2023
Modifié(e) : MathWorks Support Team
le 3 Août 2023
Live Controls such as the numeric slider use section-based execution, which, intentionally, does not clear figures. This is designed to give users the option to iterate over figures during development and to allow workflows to build up figures over time, including the creation of plots and adding annotations such as titles and more in a continuous process while advancing through each section.
As a workaround, please consider adding the following lines at the beginning of the section containing the numeric slider:
set(groot,'ShowHiddenHandles','on')
c = get(groot,'Children');
delete(c);
These lines ensure that all figures are deleted unconditionally regardless of their visibility, so adding them to beginning of the section should help resolve the large memory usage issue.
If using subplots as well within the Live Script, make sure to add the following lines of code before your subplot, instead of using the "figure" function.
rmappdata(gcf,'SubplotGrid')
clf('reset')
subplot(1,2,1)
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Graphics Objects dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!