Clear Filters
Clear Filters

Reset figures within ui figure retaining set up

14 views (last 30 days)
Katherine
Katherine on 9 Nov 2023
Answered: Yash on 14 Nov 2023
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

Answers (1)

Yash
Yash on 14 Nov 2023
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.

Categories

Find more on Develop uifigure-Based Apps in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!