File Exchange

image thumbnail

figs2tabs - move figures into a single tabbed gui

version (3.79 KB) by Chad Smith
Use MATLAB's native tab functionality to move multiple figures or GUI's into one window


Updated 18 Dec 2013

View License

--Creates a tabbed window with an existing figure moved into each tab.
--No tab workarounds necessary - MATLAB's built-in but undocumented tab
features are used for smooth graphics handling and a clean interface.

Input parameters:
figHandles: an array of handles to currently valid, visible figures.
These figures can be GUIDE based.

Output parameters:
(optional): The handle to the tabbed figure is output if desired.

f1 = figure('Name','Sin Wave');
f2 = figure('Name','Random Points');
f3 = msgbox('A message box');
tabbedFig = figs2tabs([f1,f2,f3])

This code heavily relies on undocumented Matlab functionality.
It has only been tested on Matlab 2012a. Use at your own risk.

Known limitations:
--uimenu's are not preserved
--figure-wide callback functions are not preserved, i.e. KeyPressFcn,
--resizing is not proportional (this will be fixed in a future release)

Known issues:
*Not compatible with pre r2010b versions of Matlab, though it could be with
some slight modifications to this function. Compatibility fixes
are welcome from those with older versions.

Comments and Ratings (9)

Ying Yan

Ronald DeSpain, I get the same problem. Did you address the issue?

I just ran it in 2018b, but I still get an empty figure...

This doesn't seem to work in R2016a I get a figure, but no tabs running the code above.

Error using matlab.ui.container.TabGroup/set
There is no SelectionChangeCallback property on the TabGroup class.

Maybe the ui object class has changed.
Is there another callback syntax that I can use?

Ron DeSpain

Any idea on how to make resizing proportional?


Great tool,
however, it does not seem to work with GUI's which use java.

In my case I have a GUI with a table object. However, I used some underlying java to set the row selection mode to SINGLE_SELECTION and allow rowSelection. The GUI itself works, however, when added to a tab using your tool, some errors occur.

The single row selection does not work anymore. Furthermore, if I select a cell, the following error occurs:
Error using hg.uitable/get
The name 'SelectedRow' is not an accessible property for an instance of class 'uitable'.
Somehow my table is no java object anymore?!?
And finally, when I try to add new data in my table, I get the following error:
Attempt to reference field of non-structure array.

However, I really don't this xD
Do you have any ideas?


Chad Smith

I do not have the Communications toolbox and thus I do not have the function scatterplot, so I can't replicate your error. However, this might fix your problem.

Starting at around 99, replace with the following:

%isolate type "uimenu"
%determine types of children
types = get(allChildren,'Type');
types = confirm_cell(types);
uiMenuIndxsBool = cregexp(types,'uimenu');

%add all children except those of type "uimenu"
validChildren = allChildren(~uiMenuIndxsBool);
validChildren = allChildren;


This is just what I needed, thank you!

However, I have encountered an issue while trying to use it that is outside of my programming depth: this function does not seem to like to run with scatterplots- ie, if I change the line in your sample call from "plot(sin(1:100));" to "scatterplot(0,5)", I get the following error:

Error using regexp
All cells must be strings.

Error in figs2tabs>cregexp (line 224)
bool = ~cellfun(@isempty,regexp(cellStrArray,pat));

Error in figs2tabs>add_tab (line 107)
uiMenuIndxsBool = cregexp(types,'uimenu');

Error in figs2tabs (line 54)
add_tab(tabbedFig, tabGroupH, figHandle, tabNum);

Chad Smith

The easiest way to recreate a tabbed figure in the future is to write a function that creates the individual figures, then calls figs2tabs. (Similar to what the example in the help section of figs2tabs does.) This does not save the figure, but may accomplish what you were asking.

Alternatively, if you really want to save a .fig file you can try using the commands hgsave and hgload, though the results are a little buggy.

Hope this helps!

After we make the figure with tabs how can we save that figure?


Updated description

MATLAB Release Compatibility
Created with R2012a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Discover Live Editor

Create scripts with code, output, and formatted text in a single executable document.

Learn About Live Editor