Organize several figures using tabs or docked figure

162 views (last 30 days)
I am looking for a way to organize several figures within two tabbed or docked figures. I have two functions, func1 and func2, which are each called several times (~20x) within a script. A figure with a simple plot(x,y) is generated for each run of each function, i.e. 20 figures from func1 and 20 figures from func2. I would like to consolidate these 40 figures into just two figures, one for each function. Currently, the figures are generated and visibility is set on within the functions, but I can easily pass the handles into the main workspace as outputs if required.
I haven't had much success with the uitabgroup, but would be open to suggestions. I've also tried using the docking feature (shown below) but have not been able to generate two individual docked figures.. I end up with a docked-figure containing Figures 1, 2, and 4, while Figure 3 is a "free" window. Any information on how to generate a docked figure which isn't docked to the main Matlab window is also welcomed!
set(0,'DefaultFigureWindowStyle','normal');
h1 = figure;
h2 = figure;
set(h1,'WindowStyle','docked');
set(h2,'WindowStyle','docked');
set(0,'DefaultFigureWindowStyle','normal')
h3 = figure;
h4 = figure;
set(h4,'WindowStyle','docked');
  1 Comment
Aaron Corcoran
Aaron Corcoran on 1 Nov 2019
Hi Kristin,
before this line: set(h4, 'WindowStyle', 'docked');
put this line: set(h3, 'WindowStyle', 'docked');
I hope this helps!

Sign in to comment.

Answers (1)

Sean de Wolski
Sean de Wolski on 6 Jul 2015
You just need to add tabs to the tab group. Here is an example not changing any titles/labels/sizes etc.
tg = uitabgroup; % tabgroup
for ii = 1:20
thistab = uitab(tg); % build iith tab
axes('Parent',thistab); % somewhere to plot
plot(rand(1,100));
end
  3 Comments
Kristin Busa
Kristin Busa on 7 Jul 2015
Edited: Kristin Busa on 7 Jul 2015
What I tested:
First I generated 2 figures in a separate code and saved them as fig1.fig and fig2.fig respectively:
figure; plot(1:10,3:3:30); (saved this figure via File>>save as..)
figure; plot(1:10,30:-3:3); (saved this figure via File>>save as..)
Next, after clearing the workspace and closing all figures, I ran:
h1 = open('fig1.fig'); hold all;
h2 = open('fig2.fig'); hold all;
tg = uitabgroup('Parent',h1);
for ii = 1:20
thistab = uitab(tg); % build iith tab
axes('Parent',thistab); % somewhere to plot
plot(rand(1,100));
end
The result is the first figure (was originally h1) now has 20 tabs with empty axes and its original plot is no longer visible. The second figure (originally h2) now shows both it's original plot along with the 20 random plots.

Sign in to comment.

Categories

Find more on Interactive Control and Callbacks in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!