How can I avoid repeated figure output after a section break in Live Editor?

19 次查看(过去 30 天)
If I save a figure handle and modify the figure in different sections of my code, the Live Editor keeps re-outputting those figures.
The following code ouputs the figure only once without section breaks, but 3 times with the section breaks present.
f = figure;
plot(magic(5));
% section break
f.Position = [0 0 640 480];
% section break
saveas(f,"magic.png");
If I check for f.Visible, it is already off before the repeated output.
Is it possible to somehow suppress the repeated output of figures after a section break?

采纳的回答

Cris LaPierre
Cris LaPierre 2021-8-23
I don't believe you can. This behavior is built into the design of live scripts. At each section break if anything has been done to a figure, you get a new snapshot of the figure. Perhaps it's helpful to think of it that way. These are not 3 separate figures, but snapshots of the same figure as it is modified by your code.
  4 个评论
Julian Dönges
Julian Dönges 2021-8-26
What led me to use the Live Editor that way are its control elements (buttons, check boxes etc.). I chose to work with them to avoid the time effort of creating an app (and learning to do so). Their callback functions are not accessable, instead they only allow to run the current code section.
So, in order to enable/disable each task (e.g. selecting values and creating plots, saving plots,...), I structured my code so that each section corresponds to a task. I use a check box and an if...end block for each section to set it to active/inactive, setting it to active runs that section/task. So, it's more about functional than visual separation in my case.
Cris LaPierre
Cris LaPierre 2021-8-26
That is true. Section breaks are used to control what code runs when a control is changed.
The logic, then, is if the code associated with a control modifies a figure, don't you want to see the updated figure?
If you have a reason why not, please do include those details in your feature request. Coding-wise, you clearly know what you are doing

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Environment and Settings 的更多信息

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by