Why does MATLAB consume a large amount of memory when using a numeric slider and plotting figures in a live script?

6 visualizzazioni (ultimi 30 giorni)
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? 

Risposta accettata

MathWorks Support Team
MathWorks Support Team il 2 Ago 2023
Modificato: MathWorks Support Team il 3 Ago 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)

Più risposte (0)

Categorie

Scopri di più su Graphics Objects in Help Center e File Exchange

Prodotti


Release

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by