File Exchange

image thumbnail

Manage and Dock Figures into Group

version (3.87 KB) by Anh Huy Phan
SETFIGDOCKED docks figures at specified positions in group of figures

1 Download

Updated 23 Jul 2012

View License

group = setfigdocked('PropertyName1',value1,'PropertyName2',value2,...)
- GroupName name of group need to be generated
- GridSize scalar or vector quantity, defines number of rows
and columns of cell in group
- SpanCell vector or matrix quantity, size n x 4,
[row col occupiedrows occupiedcols]
build an cell at the position (row, col) in group
cell (GridSize) which occupies "occupiedrows"
rows and "occupiedcols" columns
- Figure handle of figure
- Figindex index position of figure in group cell
- Maximize 0/1, maximize group
- GroupDocked 0/1, dock group

group = setfigdocked('GroupName','Image and Edges','GridSize',3,'SpanCell',[1 2 2 2]);
im1 = imread('cameraman.tif');
group = setfigdocked('GroupName','Image and Edges','Figure',gcf,'Figindex',2);

figure; edge(im1,'prewitt');set(gcf,'Name','Prewitt method','NumberTitle','off')
group = setfigdocked('GroupName','Image and Edges','Figure',gcf,'Figindex',1);

figure; edge(im1,'roberts');set(gcf,'Name','Roberts method','NumberTitle','off')
group = setfigdocked('GroupName','Image and Edges','Figure',gcf,'Figindex',3);

figure; edge(im1,'roberts');set(gcf,'Name','Roberts method','NumberTitle','off')
group = setfigdocked('GroupName','Image and Edges','Figure',gcf,'Figindex',4);

figure; edge(im1,'roberts');set(gcf,'Name','Roberts method','NumberTitle','off')
group = setfigdocked('GroupName','Image and Edges','Figure',gcf,'Figindex',5);

figure; edge(im1,'canny');set(gcf,'Name','Canny Method','NumberTitle','off')
group = setfigdocked('GroupName','Image and Edges','Figure',gcf,'Figindex',6);

group = setfigdocked('GroupName','Image and Edges','Maximize',1,'GroupDocked',0);

Comments and Ratings (8)

Thank you great contribution. However, i encounter some errors when running. The requested figures are indeed grouped in a single window, but the following error occurs:

setFigDockGroup: Error using set
The name 'userdata' is not an accessible property for an instance of class

Error in setFigDockGroup (line 192)

Additionally, is it possible to automatically undock the window from the matlab? So keep figures docked to a window, but not have the window itself docked to matlab?

If the figure was already docked in the Group it is not enough to select the destination tile to dock the figure to a selected position. Somehow the previous position is remembered.
As workaround reset the dock group of the figure to a hidden 'Temp' group to clear the memory of the position - before docking the figure.


One important thing to note: This script relies on a bit of a hack where some key strokes are simulated to set focus on the dock.

If, earlier in your script, you have used something like Psychtoolbox's 'ListenChar' to intercept keystrokes, then setfigdocked will not function properly. Just a friendly warning! (5 hours of debugging, and several white hairs, later..)

Still a good function though!


I was looking to make a GUI for a toolbox, involving multiple figure windows. This struck me as an elegant alternative to trying to manually keep multiple figures arranged.

Seems to work very nicely. (R2012b; Win7-64bit)


This works fine when I run it from the command window, but when I try to run it from inside a GUI, I'm getting an error. Here's the trace:

Attempt to reference field of non-structure array.

Error in setfigdocked (line 169)
jpanel.requestFocus(true); % Focus on Dock

Error in particletracking>splittifbutton_Callback (line 790)
group = setfigdocked('GroupName','Images2','GridSize',[2 3], 'GroupDocked', 0);

Error in gui_mainfcn (line 96)

Error in particletracking (line 42)
gui_mainfcn(gui_State, varargin{:});

Error in @(hObject,eventdata)particletracking('splittifbutton_Callback',hObject,eventdata,guidata(hObject))

Error while evaluating uicontrol Callback

Yair Altman

take at look at the related utility setFigDockGroup -

Really good tool. I also tried for a while how to set up groups with the DTgroup class, it takes a while to understand matlabs built-in java. So thanks very much!!!!

Great job. I've been searching the Matlab Java Archives for the appropriate objects/methods/properties for (almost) years and just could not find them. The docking of figures into seperate containers is a great way to organize your work-flow, if you have lots of figures to work with at the same time and don't want to get lost. I'll highly recommend to look into this ...


fix error caused by empty jpanel

Fixed error on Matlab 2011, and allow multiple figures docking in the same cell.

Fix errors on Matlab v2009 and later releases

Fix errors which occur MATLAB v.2009 and later release

MATLAB Release Compatibility
Created with R14SP3
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