5.0
5.0 | 9 ratings Rate this file 33 Downloads (last 30 days) File Size: 548 KB File ID: #37176 Version: 1.17
image thumbnail

Distribute figures

by

 

15 Jun 2012 (Updated )

This function can distribute figures on different parts of the screen(s).

Editor's Notes:

This file was selected as MATLAB Central Pick of the Week

| Watch this File

File Information
Description

Are you tired of moving your figures around to see them all? This function does it all for you! It can distribute in all parts of the screen, include Simulink figures or not and a whole lot more! It also supports secondary monitor(s) where the figures can be distributed.
>>>> A sample image can be found here: http://oi60.tinypic.com/9amydc.jpg <<<<<
The function calls needed to distribute in the shown pattern above is only:

distFig('Pos','NW','Only',1);
distFig('Pos','SW','Cols',3,'Only',(2:4));
distFig('Pos','NE','Rows',2,'Only',5);
distFig('Pos','NE','Rows',2,'Cols',2,'Only',[6,7],'Offset',2,'transpose',true);
distFig('Pos','SE','Rows',2,'Cols',4,'Only',(8:11));
distFig('Pos','SE','Rows',3,'Cols',2,'Not',(1:11),'Offset',3);

(Don't worry - it looks complicated, but by executing distFig(); the figures will also be nicely distributed. :) ) Also, there are two tutorials included to guide you through the various features.

The function supports all resolutions (also different resolutions on different monitors). It has been made using MATLAB 2015a and will thus not work properly for version 2014a and previous due to the changes in the figure handle system in version 2014b a newer releases.

The function also detects new updates automatically, but this feature is very beta, so it might contain bugs. It can easily be disabled without affecting the function, if it causes problems. Please report any errors encountered with the function. :)

Syntax:

distFig(...,'Screen',Value)
distFig(...,'Position',Value)

distFig(...,'Rows',Value)
distFig(...,'Columns',Value)

distFig(...,'Not',Value)
distFig(...,'Only',Value)
distFig(...,'Offset',Value)

distFig(...,'Adjust',Value)
distFig(...,'Extra',Value)
distFig(...,'Menu',Value)
distFig(...,'Transpose',Value)
distFig(...,'Simulink',Value)
distFig(...,'Tight',Value)
distFig(...,'Scale',Value)
distFig(...,'ScaleOrigin',Value)
distFig(...,'FreezeSize',Value)
distFig(...,'Order',Value)

Description:

distFig(...,'Screen',Value) assigns where the figures will be distributed. Synonyms for 'Screen' are 'Scr' and 'S'. Value can be:
'C' / 'Center' (Default)
'W' / 'West' / 'L' / 'Left'
'E' / 'East' / 'R' / 'Right'
'N' / 'North' / 'T' / 'Top'
'S' / 'South' / 'B' / 'Bottom'
'Main' / 'Primary'
'Ext' / 'External' / 'Secondary'

distFig(...,'Position',Value) assigns in which part of the screen the figures will be distributed. Synonyms for 'Position' are 'Pos' and 'P'. Value can be:
'C' / 'Center' (Default)
'W' / 'West' / 'L' / 'Left'
'E' / 'East' / 'R' / 'Right'
'N' / 'North' / 'T' / 'Top'
'S' / 'South' / 'B' / 'Bottom'
'NW'
'NE'
'SW'
'SE'

distFig(...,'Rows',Value) assigns how many rows the figures will be distributed on. Synonyms for 'Rows' are 'R'. Value can be:
1...n
'Auto' / -1
'Auto' indicates that it automatically calculates the number of required rows.

distFig(...,'Columns',Value) assigns how many rows the figures will be distributed on. Synonyms for 'Columns' are 'Cols' and 'C'. Value can be:
1...n
'Auto' / -1
'Auto' indicates that it automatically calculates the number of required columns.

distFig(...,'Not',Value) excludes specified figures from the distribution list. Value must be an array with the excluded figure numbers. The default value is []. The input argument 'gcf' (get current figure) can be used as well.

distFig(...,'Only',Value) does only distribute specified figures. Value must be an array with the figure which will be distributed. The default value is []. The input argument 'gcf' (get current figure) can be used as well.

The remaining features are described in the file.

Required Products MATLAB
MATLAB release MATLAB 8.5 (R2015a)
MATLAB Search Path
/
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (42)
16 Jun 2015 Anders Simonsen

@arnold: Hi. Okay, I'll take a look at it in the next update. I've encountered some bugs with the 'tight' command as well, so I'll make sure it's working properly.

Comment only
14 Jun 2015 arnold

arnold (view profile)

Hi Anders,

the 'tight' property doesn't work properly if one uses suptitle (and I use it a lot). distFig then cuts of the xlabel of plots.

kind regards
arnold

Comment only
03 May 2015 Luke

Luke (view profile)

So very useful... Thank you Anders

07 Apr 2015 Anders Simonsen

@Alia: I'm not supporting MATLAB 2014a and previous releases due to the changes in the graphics structure within the 2014b and newer releases. Sorry :|

Comment only
07 Apr 2015 Alia

Alia (view profile)

Hello,

I still have this error msg:
Attempt to reference field of non-structure array.

Error in distFig (line 454)
Fig_Number = {Fig_Object.Number};

Error in Sample (line 28)
distFig('Pos','NW','Only',1,'Tight',true);

I am using MatlabR2014a, how is it possible to solve it

Comment only
10 Mar 2015 Anders Simonsen

@Michael: Thanks! And sorry for the late answer. Sure, I'll make sure to add that to the next update, which will follow soon. :)

Comment only
23 Feb 2015 Michael

Hello Anders,
Impressive work! It's a very nice and handy function. Would you consider adding an option to not resize figures, but distribute them with their current size? That would help a lot.
Thanks,
Michael

Comment only
19 Jan 2015 Ke Wang Helmersson

I don't know why I got monitor matrix which didn't have an origin at [1, 1]. I had 'dbstop if error' and ran get(0,'MonitorPositions') at dbstop. I couldn't reproduce it either since there is no error.

Comment only
19 Jan 2015 Anders Simonsen

Okay, perfect! Also, you can see that your monitors are detected "correctly" this time. I don't know how you got your previous monitor matrix, which hadn't got an origin at [1,1].

Comment only
19 Jan 2015 Ke Wang Helmersson

Now my extended display works also. Thanks!

Comment only
19 Jan 2015 Ke Wang Helmersson

Yes, I was a bit surprised to see that I had only one row when I checked monitor. After restarting the matlab, the monitor matrix becomes:
Monitors =

-1365 1 1366 768
1 1 1920 1200

Comment only
19 Jan 2015 Anders Simonsen

Okay, it seems like you only have a single monitor. The number of rows in the monitor matrix is the number of monitors:

[Origin_x , Origin_y , Width , Height]

Mine yields:

[1,1,1920,1080
-1919,1,1920,1080]

Can you describe your setup?

Btw. MATLAB does not recognize changes in the monitor configuration, AFTER it has been started. So if you plug in your monitor AFTER you started MATLAB, it will not detect it - so try and restart MATLAB and see if that works.

Comment only
19 Jan 2015 Ke Wang Helmersson

Yes, I got a warning message. Here is the monitor matrix.
Monitors =

1 1 1920 1080
Ke

Comment only
19 Jan 2015 Anders Simonsen

@Chad: Thanks! :D

@Ke Wang: Yearh - you should be able to. Does you come with a warning message? Can you post your monitor matrix again (Monitors = get(0,'MonitorPositions');)? (If it has changed?)

You can see my setup here, where I made a brief description of how to distribute to external monitor(s). http://s000.tinyupload.com/index.php?file_id=63083430746980020338

Comment only
19 Jan 2015 Ke Wang Helmersson

Hello Anders, I wonder if I can distribute figures to extended displays. It seems that the function doesn't consider it as external monitor and couldn't find it.

Comment only
18 Jan 2015 Chad Greene

Chad Greene (view profile)

That is the finest FEX submission icon I have ever seen. Well done.

Comment only
18 Jan 2015 Erik

Erik (view profile)

 
17 Jan 2015 Anders Simonsen

@Ke Wang: Thanks a lot! :D I thought it might help with some of the features. :) I plan on making more tutorials soon.

Comment only
17 Jan 2015 Ke Wang Helmersson

It works very well now. Thanks for the function!

Comment only
17 Jan 2015 Ke Wang Helmersson

And the tutorial is great!

17 Jan 2015 Anders Simonsen

@Ke Wang: Hmm - that's weird. Usually the primary monitor has origin in [1,1], but yours seem to be located at [1,121]. I couldn't reproduce your settings, as I instead got:

-1365 153 1366 768
1 1 1920 1080

But I've just uploaded a new version, where the primary monitor is detected by minimizing the absolute sum of the two first columns, so it should work for you now, if you just download the latest one. :)

Comment only
17 Jan 2015 Ke Wang Helmersson

Thanks for your quick reply. Here is the matrix:
Monitors =

-1365 273 1366 768
1 121 1920 1080

Ke

Comment only
17 Jan 2015 Anders Simonsen

@Ke Wang: All right - I don't know what causes that. Can you evaluate the following in your Matlab workspace and send me the resulting matrix:

Monitors = get(0,'MonitorPositions');

Monitors is a (n x 4) matrix, where n is the number of monitors you have.

Comment only
16 Jan 2015 Ke Wang Helmersson

I have tried Sample.m in MATLAB2014b and got following error:
Warning: Screen 'C' could not be found!
> In distFig at 382
In Sample at 21
Index exceeds matrix dimensions.

Error in distFig (line 408)
x = round(linspace(Limit{2}(1),Limit{2}(2),Cols + 1) * Monitor(3)) + 1;

Error in Sample (line 21)
distFig('Pos','NW' , 'Only',1);

408 x = round(linspace(Limit{2}(1),Limit{2}(2),Cols + 1) * Monitor(3)) + 1;

Comment only
07 Jan 2015 Anders Simonsen

@Ramin: The function will not work for Matlab version 2014a and previous. This is due to the massive overhaul of the graphics handle system in 2014b and forward.
You can try and rewrite the lines that are not working, as I'll not support version 2014a and previous anymore - sorry. :)

Comment only
07 Jan 2015 Ramin Rajabioun

running Sample.m produces an error like this on my MATLAB 2014a:

Attempt to reference field of non-structure array.

Error in distFig (line 322)
Fig_Number = {Fig_Object.Number};

Error in Sample (line 21)
distFig('Pos','NW' , 'Only',1);

Comment only
22 Oct 2014 Anders Simonsen

@Mike: Thanks - so do I. ;)

Okay, thanks for the feedback and for finding and fixing the problem! :D I'll make sure to include it in the next version of it.

I've also stumbled upon a few bugs as well, which aren't working properly after the 2014b release, so I'll update it again soon.

Comment only
22 Oct 2014 Mike

Mike (view profile)

Very nice feature, I use it all the time :)

Had a little compatibility issue with the newly released R2014b. Since figure handles are no longer numbers but figure objects, the sort feature no longer works. Hence, the figures get distributed nicely, just not in the right order. I fixed this by accessing the Number property of the figure objects instead. (see below)

My code adaptation, first line of 'Generate figure list' section:
ORIGNAL CODE:
Fig_List = findall(0,'type','figure');

MY ADAPTATION:
Fig_Object = findall(0,'type','figure');
Fig_List = [Fig_Object.Number];

This way, Fig_List is a vector of numbers again that can be sorted a few lines below ;) Not sure if it's the neatest way, but works fine for me :)

07 Sep 2014 Anders Simonsen

@arnold: Can you send me an example code, where you are having the problem? Then I can take a look at it. :) (Btw. I've sent you a private message as well)

Comment only
04 Sep 2014 arnold

arnold (view profile)

hi anders.
I've integrated the 'tight' argument in many of my functions but just saw that it is cutting off any xlabel one adds to a boxplot... no idea why xlabels of boxplots are treated entirely different than those of other plots.

Comment only
20 Aug 2014 Anders Simonsen

@arnold: I've just updated it again and now it should work. I didn't test it yesterday on 2014a as I didn't have acces to it, but now I have done that and fixed the error.

It is caused by the new way that the figure system is made in 2014b, which has been changed a lot! The only thing you should do is to download it again or just delete the line that is causing the error. :)

Comment only
20 Aug 2014 arnold

arnold (view profile)

@ Anders: thanks for the update. Unfortunately the function does not work anymore, no matter what type of figures are open. i.e. opening four figures, no content, then executing 'distFig' with no arguments. Gives the following error on 2014a:

Improper index matrix reference.

Error in distFig>@(n)(Figs(n).Number) (line 199)
Figs = sort(arrayfun(@(n) (Figs(n).Number),1:numel(Figs)));

Error in distFig (line 199)
Figs = sort(arrayfun(@(n) (Figs(n).Number),1:numel(Figs)));

Comment only
19 Aug 2014 Anders Simonsen

@arnold: I've just updated the function to support the other function. The problem was that "fig()"; changed 'Units' to 'centimeters', whereas my function was using 'pixels'. Furthermore, I've added a new feature called distFig(...,'Tight',true/false), which can remove the whitespace around the figure like "fig();" - if that is what you're looking for. :)

And thanks for the feedback. :)

Comment only
19 Aug 2014 arnold

arnold (view profile)

for some reason 'distFig' can't deal with figures produced by 'fig' from the fileExchange, which is also a great tool:
http://www.mathworks.com/matlabcentral/fileexchange/30736-fig-the-exact-figure-size-and-no-white-space

The figures disappear from the screen even though they're still opened.

Comment only
04 Jun 2014 Anders

Anders (view profile)

Often i used to be both tired and depressed - but then I tried Quack Simonsen's mircale function. Now I feel much better - thanks Simonsen!

29 May 2014 Anders Simonsen

@Ivan: Sorry for the late response. Yes - the new function does support different screen resolutions. :)

Comment only
31 Mar 2014 Ivan

Does it support different screen resolutions? Or just 1920*1080?

Comment only
29 Nov 2013 Mark Søndergaard Sørensen

Exactly what I was looking for and easy to use.

29 Nov 2013 Tobias Olesen

Great funktion!

27 Jul 2012 H

H (view profile)

Thanks!

20 Jun 2012 Anders Simonsen

Thanks. So I assume you would have preferred something like distFig('Position','Left','Screen','Right');?

Comment only
20 Jun 2012 Deborah

Deborah (view profile)

Nice function. Although I think it doesn't make any sense to accept multiple character input like 'r','l' since only the last input is used by the function.

Updates
18 Jun 2012 1.2

Removed a misplaced "nargin".

02 Jul 2012 1.3

Added the 'Rows' and 'Offset' properties and changed the input mode a more logical way.

03 Jul 2012 1.5

Added a few lines to the description.

06 May 2013 1.6

A minor update

29 May 2014 1.7

The whole function has been updated to support different screen resolutions along with other useful features.

02 Jun 2014 1.8

Updated description

19 Aug 2014 1.9

Added support for the 2014b (pre)release. Also fixed a minor problem with the 'Units' property of the current axes.

20 Aug 2014 1.10

Fixed a minor bug with the new figure handle system of 2014b.

20 Dec 2014 1.11

The function has been updated to support the new figure handle system of 2014b and 2015a (Prerelease). Minor bugs have been fixed as well.

17 Jan 2015 1.12

Added improved relative monitor detection.
Added exceptions for special function calls, which caused errors.
Fixed minor bugs.
Added automatically update feature system (First attempt of doing so, so it might cause bugs - please report these)

17 Jan 2015 1.13

Added a tutorial file.

17 Jan 2015 1.14

Fixed a minor bug causing incorrect detection of primary monitor.

18 Jan 2015 1.15

Added a second tutorial and added an 'Adjust' feature.

29 Mar 2015 1.16

Added support for 'gcf' (get current figures) when using the 'only' and 'not' features.
Added features: 'Scale', 'ScaleOrigin', 'FreezeSize' and 'Order'.
Added additional warnings if external monitor(s) cannot be found.
Minor bug fixes.

31 Mar 2015 1.17

Fixed a minor bug with the 'only' and 'not' features when using the 'gcf' input.

Contact us