File Exchange

image thumbnail


version (66.3 KB) by Yair Altman
Sets a figure's docking group container


Updated 09 Dec 2020

View Version History

View License

setFigDockGroup sets a figure's (or list of figures') docking group container, enabling to dock figures to containers other than the default 'Figures' container (for example, to the 'Editor' group as shown in the screenshot, or to any new user-defined group, or even to another figure's button).

hGroup = setFigDockGroup(hFig, group)
hButton = setFigDockGroup(hFig, hButton)

hFig is an optional handle or list of handles. These are normally figure handles, but not necessarily: the handles' containing figures are automatically inferred and used. If hFig is not supplied, then the current figure handle (gcf) is assumed.

group is either a group name (e.g., 'Editor', 'Figures', 'my group') or a group handle returned from a previous setFigDockGroup function call.

hButton is the handle of a uicontrol pushbutton on another figure. This button would typically be labeled "undock" or have an undocking icon. Note that the docked figure will be minimized to the target hButton - you will NOT be able to see the docked figure's contents in the target figure, only to undock it via the button. Docking into a figure panel will perhaps be added in some future version.

The returned hGroupContainer object allows access to many useful properties and callbacks. Type "get(hGroupContainer)" to see the full list. Note that hGroupContainer may return empty ([]) if the group container is not visible.

See extended help within.

This code heavily relies on undocumented and unsupported Matlab functionality. It works on Matlab 7.4+, but use at your own risk!
This utility does NOT work with uifigures (created using the uifigure function or App Designer) - only with legacy (Java-based) figures.

Bugs and suggestions:
Please send to Yair Altman (altmany at gmail dot com)

Cite As

Yair Altman (2021). setFigDockGroup (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (19)

Yair Altman

The latest version that I just uploaded includes fixes for the issues reported below (thanks!). The new version is compatible with all Matlab releases up to R2020b.

Thomas Flick

This code worked great with a few changes... Apparently, the "getGroupContainer" method does not get a group container. So, I replaced this "getGroupContainer" method with "addGroup". After I did this, line 193 reads:
hContainer = desktop.addGroup(group);
Then, I commented out this line (line 196):
You don't need to set userdata to save the group name because you will see the group name is already saved in the hContainer.

Markus Sause


did take me a little while to get back to this. I am quite convinced now, that figure docking is deactivated in deployed apps. I checked the status of hFig1 immediately after line 181

set(hFig1,'WindowStyle','docked'); drawnow

Still says 'normal' rather than 'docked'. Also tried several more versions to be sure it did not loose ots handle to the figure to be docked. No success.

This behaviour is additionally supported by the MATLAB officials:

But works PERFECT in regular MATLAB environment, hence the 5*

Markus Sause

Yair Altman

Markus - no special treatment of deployed apps was done in this submission. If it works then great; if not, you'd need to either (1) find another solution, or (2) adapt the submission to fit your needs, or (3) hire my time to investigate the problem and see if I can solve it (something which is not assured).

Markus Sause

Hi Yair,
Is there any new hack to this submission since 2018b release? Docking seems to work fine within the MATLAB environment, but fails with the compiled version (using the Application compiler). Do not see any warnings during compilation that could be helpful for debugging though.
Also no errors/warnings when running inside Matlab. Was this release ever intended to work with the deployed apps?


Jim Hokanson

Hi Yair,

A few things. On 2016b, I needed to comment out setting the userdata for the container, similar to Ian's message. I am also a bit confused by the usage, since it seems like the function just associates the docking group and doesn't actually dock the figure. Commenting out setting the oldStyle fixes this (line 182?). This is fine and could be fixed with an optional input, but it seems to contradict the documentation.


Ian Phillips

Hi Yair,
If I use: set(0,'DefaultFigureWindowStyle','docked')

hFig1 = figure('Name','One');
hGroupContainer = setFigDockGroup(hFig1, 'myFigGroup');

I get the following error:
setFigDockGroup: Error using set
The name 'userdata' is not an accessible property for an instance of class

Error in setFigDockGroup (line 196)

Error in test_setFigDockGroup (line 14)
hGroupContainer = setFigDockGroup(hFig1, 'myFigGroup');

If I use:

hFig1 = figure('Name','One');
hGroupContainer = setFigDockGroup(hFig1, 'myFigGroup');

Everything works ok. Is this a know issue?
I am using Matlab 2016a.

thanks for your help.

Yair Altman

@Jochen - the hGroupContainer returns empty ([]) if the group container is not visible.

Clemens Nyffeler


Dear Yair,
thanks for all your effort. I am successfully using multiple of your other submissions, but can't get this one to work on (R2015b).

hFig = figure('Name','One');
hGroupContainer = setFigDockGroup(hFig,'My App')

Returns an empty hGroupContainer, i.e. [].

Your generous help is greatly appreciated.


Error in version R2014a.

line192: set(hContainer,'userdata',group);

throws error:

The name 'userdata' is not an accessible property for an instance of class 'com.mathworks.widgets.desk.DTDocumentContainer'.

Clemens Nyffeler

This function is awesome!

Apparently the dock group window remembers its last layout (i.e. how many tiles it has and where they are located).
Is it possible to control which tile a given figure goes into?

Yair Altman

Jonathan - yes, this utility can indeed be used in deployed apps. If you need consulting help regarding docking, or Matlab in general, please contact me offline (altmany at gmail).

Jonathan Lister

Can this be used in deployed applications?

Brian B

This is exactly what I was searching for!

Feature requests:

1) add functionality to close these docked group windows groups! ('close all' doesn't do the trick, as the group container remains)

2) keep the grouped windows from populating Matlab's Desktop menu list (The drop down alongside File | Edit | Debug |... ). It seems to include every single grouped window I create :(

almog shalom

Very nice!
Another useful function by Yair Altman.
On R2009a, JavaFrame still works, and I guess that when it won't work, there will be a replacement (I'm sure that Y. Altman will find it even it will be undocumented ;) )

jun ziyang

Very Usefull!
But the figure JavaFrame property will be obsoleted after R2008a. Hope there is a way around.

Dan Haeg

Great function.

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

Inspired: DOCK and UNDOCK figures into groups

Community Treasure Hunt

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

Start Hunting!