MATLAB: Removing blankspaces from a figure containing subplots

MATLAB

I have [1 x 2] subplots, which I am trying to use in the Live Editor. How do I increase the width of the subplots, while also decreasing the white spaces above and below the plots?

Best Answer

The commands below create a figure with [1 x 2] subplots.
figure()
sb1 = subplot (1,2,1); plot (1:10);
sb2 = subplot (1,2,2); plot(10:10);
However, when used in a live script or any other doc format, it inserts a significant amount of whitespace above and below the subplots.
These white spaces can be removed by appropriately specifying the size and position of the figure window and the subplots.
The code above can be modified as follows:
figure ()
set (gcf, 'Position', [300 300 700 500])
% The default unit for figure Position is pixels
sb1 = subplot (1,2,1);
sb1.Position = [0.05,0.05,0.4,0.85];
plot (1:10);
sb2 = subplot (1,2,1);
sb2.Position = [0.55,0.05,0.4,0.85];
plot (1:10);
% subplot Position default unit is 'normalized'. Specifying the fourth element of the vector as 0.85 ensures that the subplot height occupies 85% of the figure window
The four element vectors above can be modified as per the requirements, but the fourth element of sb1.Position and sb2.Position are significant as they reflect the percentage of the figure height that is occupied by the subplots.
For specifying the position of the figures and axes properties, refer to the links below