Why does MATLAB consume a large amount of memory when using a numeric slider and plotting figures in a live script?
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
MathWorks Support Team
el 22 de Jun. de 2023
Editada: MathWorks Support Team
el 3 de Ag. de 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?
Respuesta aceptada
MathWorks Support Team
el 2 de Ag. de 2023
Editada: MathWorks Support Team
el 3 de Ag. de 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 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Graphics Objects en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!