Reset figures within ui figure retaining set up

5 次查看(过去 30 天)
I have a code that generates a uifigure. Then it populates this figure with graphs, table and a map. I then run a function and it populates these figures, graphs map etc.
I want to create some code to check if the figures, graphs map etc. have been populated and if so clear then to run other functions, without having to reset up the ui figure

回答(1 个)

Yash
Yash 2023-11-14
Hi Katherine,
I understand that you're interested in verifying whether a uifigure is populated or not and, if so, you'd like to remove the graphs for subsequent functions. To accomplish this, you can make use of the "Children" property of the uifigure. Please refer to the example below, which checks for the presence of a graph on the uifigure:
% Create a uifigure
fig = uifigure;
% Populate a graph onto the figure
ax = uiaxes(fig);
x = 0:0.01:2*pi;
plot(ax,x,sin(x));
% Check for the Children
fig.Children
% You can put a check on the length for the if condition
length(fig.Children)
% Clear / remove the Children
delete(fig.Children)
% Check for the Children
fig.Children
length(fig.Children)
If you are specifically interested in checking whether the graph is populated or not, you can examine the "Children" property of the axes as well:
ax.Children
Hope this information helps you address the issue.

类别

Help CenterFile Exchange 中查找有关 Develop uifigure-Based Apps 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by