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

6 次查看(过去 30 天)
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? 

采纳的回答

MathWorks Support Team
编辑:MathWorks Support Team 2023-8-3
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 个)

类别

Help CenterFile Exchange 中查找有关 Graphics Objects 的更多信息

产品


版本

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by