MATLAB: Does the size of a figure change slightly when the ‘resize’ option is enabled even if the ‘OuterPosition’ property is fixed in MATLAB 8.0 (R2012b)

MATLAB

I have created a figure in the following way:
fig = figure('OuterPosition', [100 500 550 400], 'resize', 'on');
If I now change the property 'resize' to off, I can observe that the size of the figure has changed. However, the 'OuterPosition' is maintained constant.
set(fig, 'resize', 'off' );
get(fig, 'OuterPosition')

Best Answer

This change of the size that is observed when changing the 'resize' property but maintaining the 'OuterPosition' fixed is an intended behaviour.
There are two properties that affect the position of a figure, the property 'Position' and the property 'OuterPosition'. The figure 'Position' specifies the size and location on the screen of the figure window, not including title bar, menu bar, tool bars, and outer edges, whereas the 'OuterPosition' property includes title bar, menu bar, tool bars, and outer edges.
When allowing the resize option, the figure window changes in a subtle way, and MATLAB deals with it by changing one of the position properties. Therefore, either the inside of the figure needs to change size or the outside does. You will need to specify the size of the property that you want to hold constant.
For example, the following code shows how the properties 'Position' and 'OuterPosition' change when 'resize' is enabled/disabled depending on which property is fixed:
fig = figure('OuterPosition', [100 500 550 400], 'resize', 'on');
for i = 1:5
set(fig, 'resize', 'on');
fprintf('Figure 1: Resize = %s, Position = [%.0f %.0f %.0f %.0f], OuterPosition = [%.0f %.0f %.0f %.0f]\n', ...
get(fig,'Resize'), get(fig,'Position'), get(fig,'OuterPosition'));
pause(0.5)
set(fig, 'resize', 'off');
fprintf('Figure 1: Resize = %s, Position = [%.0f %.0f %.0f %.0f], OuterPosition = [%.0f %.0f %.0f %.0f]\n',...
get(fig,'Resize'), get(fig,'Position'), get(fig,'OuterPosition'));
end
pause(0.5);
fig2 = figure('Position', [708 508 534 308], 'resize', 'on');
for i = 1:5
set(fig2, 'resize', 'on');
fprintf('Figure 2: Resize = %s, Position = [%.0f %.0f %.0f %.0f], OuterPosition = [%.0f %.0f %.0f %.0f]\n',...
get(fig2,'Resize'), get(fig2,'Position'), get(fig2,'OuterPosition'));
pause(0.5)
set(fig2, 'resize', 'off');
fprintf('Figure 2: Resize = %s, Position = [%.0f %.0f %.0f %.0f], OuterPosition = [%.0f %.0f %.0f %.0f]\n',...
get(fig2,'Resize'), get(fig2,'Position'), get(fig2,'OuterPosition'));
end
By running this code it is possible to observe that if the size that users observe visually, is the one that needs to be fixed, the property that needs to be held constant is 'Position' instead of 'OuterPosition'.