File Exchange

image thumbnail

tilefigs

version 1.1 (3.91 KB) by

MATLAB function for tiling figures on the screen.

11 Downloads

Updated

View License

Inspired by http://www.mathworks.com/matlabcentral/fileexchange/328-tilefigs-m , but with a number of improvements. User can choose which figures to tile, can resize or not, can specify a number of rows and/or columns, can specify a spacing between the figures, and can specify a sub-portion of the monitor to be used.

tilefigs also allows tiling on a dual monitor, though MATLAB does not (at present) officially support multiple monitors, and so some manual effort may be required.

Comments and Ratings (13)

Wonderful function, thanks a lot!
However, I made the following mod in the final lines to avoid a crash if there is only one figure present:

%%%%%
% This part was modified on March 21, 2017 by Kristoffer Kjærnes. 'units' is
% not a cell array if there is only one figure present. This mod prevents a
% crash.
if nFigures == 1
set(handles(ii),'units',units);
else
for ii = 1:nFigures
set(handles(ii),'units',units{ii});
end
end

%%%%%

By the way, John Smith's comment 20 Feb 2016 seems appropriate to implement as well.

John Smith

Great utility!
There's a problem, though:
The program changes figure units to 'pixels' while running and reverts back to whatever units the figure had.
However, since the units were changed from 'normalized', resizing of the figure does not resize text, labels, etc. Therefore, they get clipped.
It'd much better to operate with 'normalized' units.

Arnold

Arnold (view profile)

Thank you!! Pico's suggestion also works great on my linux machine.

Thanks for a great function!
Note - For those who are in search of a function which is optimized for tiling figures of different sizes, you might want to try my arrangeFigures

http://www.mathworks.com/matlabcentral/fileexchange/52774-arrangefigures--handles--

i love this function, but all of a sudden now I got the following error (which I can not understand nor solve):

Error using set
Width and height must be > 0
Error in tilefigs (line 169)
set(handles(pnum),'OuterPosition',[xLocation yLocation width height]);

I appreciate any help! working in matlab R2013b (8.2.0.701) in mac OS 10.9.4

thanks

Peter Pablo

Works very well as described on my linux machine.

Rico

Rico (view profile)

Thanks for this nice function!

There is one problem, though, when you are running matlab in linux. In this case 'MonitorPositions' has a different meaning (see http://www.mathworks.de/de/help/matlab/ref/rootobject_props.html).

Thus, linux users need to replace

matlabMonitorSize = monitorPositions(:,3:4) - monitorPositions(:,1:2) + 1;

with

matlabMonitorSize = monitorPositions(:,3:4);

Jonathan

I love this function, it is very useful and works well.

My only issue is that (as you describe in the comments) it does not correctly position the figures on multi-monitor setups. This is because get(0,'MonitorPositions') returns the monitor boundaries in 'display' coordinates with (1,1) at the upper left corner of monitor 1, while figure positions start at the lower left corner.

If you replace your definition of 'matlabMonitorLocation' with:
matlabMonitorLocation = [monitorPositions(:,1) (monitorPositions(1,4) - monitorPositions(:,4) + 1)];

it works perfectly (at least on my 4 monitor Windows 7 setup on MATLAB R2013a).

Brendan

Brendan (view profile)

Anne, to fix the fact that the images don't go all the way down the screen, you can edit the default border.

% Set the default border if none is specified [left, bottom, right, top]
if monitor > 1
if ~exist('border','var') || isempty(border)
border = [0 0 0 0];
end
else
if ~exist('border','var') || isempty(border)
border = [0 30 0 0];
end
end

Change the second border to [0 0 0 0]

Are you setting resize to false? If not, I don't understand the issue with the figure overlap. Tilefigs uses the "outer position" information from the figure handle, so either there is an error in my math somewhere, or matlab does not compute the outer position of the figures properly. A hack to fix this would be to add in a leftRightSpacing ( or topBottomSpacing), though I agree it's not ideal.

Anne

Anne (view profile)

Great function—thank you for sharing it!

The only issue for me (I'm on Mac OS 10.6.8) is that there is some overlap between the windows, and they don't go quite all the way down to the bottom of the screen. But that's a very minor thing—otherwise it works great.

Awesome function! I now use it a nearly all my simulations. You can very easily sort your figure just by doing (for example):

h(1) = figure();
...
h(2) = figure();
...
h(3) = figure();
...
h(4) = figure();
...
h(5) = figure();
...

tilefigs(h);

And that's it! All your figures are placed correctly on the screen so you can analyse easily and conveniently all your results. A must have.

Brendan

Brendan (view profile)

Updated to allow for non-pixel units for figures

Updates

1.1

Changed to allow arbitrary figure units (instead of forcing pixels)

MATLAB Release
MATLAB 7.12 (R2011a)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Win prizes and improve your MATLAB skills

Play today