Automatically maximize a figure
This worked for me:
figure('units','normalized','outerposition',[0 0 1 1])
or for current figure:
set(gcf,'units','normalized','outerposition',[0 0 1 1])
I have also used MAXIMIZE function on FileExchange that uses java. This is true maximization.
For an actual Maximize (exactly like clicking the maximize button in the UI of OS X and Windows) You may try the following which calls a hidden Java handle
figure;
pause(0.00001);
frame_h = get(handle(gcf),'JavaFrame');
set(frame_h,'Maximized',1);
The pause(n)
is essential as the above reaches out of the Matlab scape and is situated on a separate Java thread. Set n
to any value and check the results. The faster the computer is at the time of execution the smaller n
can be.
Full "documentation" can be found here
As of R2018a, figure
as well as uifigure
objects contain a property called WindowState
. This is set to 'normal'
by default, but setting it to 'maximized'
gives the desired result.
In conclusion:
hFig.WindowState = 'maximized'; % Requires R2018a
Furthermore, as mentioned in Unknown123's comments:
-
Making figures maximized by default is possible using:
set(groot, 'defaultFigureWindowState', 'maximized');
-
Maximizing all open figures is possible using:
set(get(groot, 'Children'), 'WindowState', 'maximized');
More information about
'WindowState'
as well as other properties controlling figure appearance can be found in this documentation page.
Finally, to address your original problem - if you want to export the contents of figures to images without having to worry about the results being too small - I would highly recommend the export_fig
utility.