Purpose
'arrangeFigures' arranges figures into a grid on a screen. No input parameters required, but possible for fine tuning.
Features
Detects all figures with HandleVisibility='on'. This is on purpose, because in most cases you don't want to move e.g. GUIs .
Without fine tuning parameters all figures are placed on the total screen of the second monitor. If the second monitor doesn't exist, the primary monitor is used.
Syntax
arrangeFigures %Automatic mode
or
arrangeFigures(frame_position, monitor, aspectRatio, hFigs, numRows, numCols, removeMenu)% Full fine tuning
Fine tuning
All parameters are optional.
1.) frame_position: position where the figures are placed, vector [x-position, y-position, width, height], optional
numbers >= 1 are treated as pixels
numbers < 1 are treated as relative values, e.g. width = 0.5 means half of the screen width
Any value set to 0 will be set to a value for use of the remaining space
The default value for the y-position is set 40 for the task bar of Windows system.
frame_position = 0 -> the full screen is used
2.) monitor: number of the monitor to display the figures, integer number, optional
monitor = 0 or monitor not found -> use by preference the second monitor (default)
If the default monitor is not present, use primary monitor
3.) aspectRatio: aspect ration (width/height) of figures, double number, optional
aspectRatio set -> force figure size, the frame width or height may be partially empty
aspectRatio = 0 or not set -> fill out the available frame_position
4.) hFigs: a vector with the figure handles, optional
hFigs = 0 -> all figures that have HandleVisibility='on' (e.g. no GUI) are arranged in a grid.
Matlab's default is HandleVisibility='on'. If you want all figures, uncomment line 117.
5.) numRows: number of rows for the grid, integer number, optional
numRows = 0 -> the number of colums is calculated according to the number of columns
6.) numCols: number of columns for the grid, integer number, optional
numCols = 0 -> the number of rows is calculated accordingly
numRows = 0 and numCols = 0 or not set -> both calculated according to the disponible area.
7.) removeMenu: remove the menu bar and the tool bar, string or 0, optional
'yes' -> remove the menu bar and the tool bar. Warning: Both bars are permanently removed.
Any other string or number will not affect the figures.
For easy setting of the parameters and preview of the layout you may use the included GUI.
REMARKS
All input parameters are optional. If you have a trailing paremeter set, the previous parameters must all have the placehoder 0.
For example:
arrangeFigures(0.5, 2, 0, 0, 3 ) % arranges the figures on the right half of the second screen, 3 rows
. The two zeros in the middle are place holders.
EXAMPLE
Seven or eight figures are arranged into a grid.
numFigures = 7;
hFigs = zeros(numFigures,1);
x = 0:0.01:2*pi;
for i = 1:numFigures
hFigs(i) = figure;
plot(x, sin(i*x));
end
figure('Position',[100,100,2000,900]); plot(x, x); % Extra figure not in fig_list
arrangeFigures(0,0,0,hFigs) % Arrange the selected figures on the screen
pause(2)
arrangeFigures % Arrange all figures automaticly on the screen
pause(2)
arrangeFigures([0.6,0.4],2,10/9,0,2) % [0.6,0.4]: Put all figures on the upper right side of the screen.
% 2: Use second monitor
% If the second monitor is not present, use primary monitor.
% 10/9: Force the aspect ratio (width/height) to 10/9.
% 0: Process all figures with HandleVisibility='on'.
% 2: Put all figures in 2 rows.
You may also be interrested in a file to close many figures:
https://de.mathworks.com/matlabcentral/fileexchange/61974-gui-to-close-all-open-figures-except-those-selected
引用格式
Peter Seibold (2024). Arrange figures into a grid (https://www.mathworks.com/matlabcentral/fileexchange/164141-arrange-figures-into-a-grid), MATLAB Central File Exchange. 检索时间: .
MATLAB 版本兼容性
创建方式
R2020a
兼容任何版本
平台兼容性
Windows macOS Linux标签
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!