View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from

4.6 | 22 ratings Rate this file 25 Downloads (last 30 days) File Size: 1.24 KB File ID: #25471 Version: 1.3




02 Oct 2009 (Updated )

Platform independent function to maximize a figure window.

| Watch this File

File Information

This function maximizes MATLAB figures on any platform. It takes a figure handle as input. Note: it doesn't simply resize the figure to fill the screen.

It uses Java, therefore doesn't contain any mex or OS specific code.


Findjobj Find Java Handles Of Matlab Graphic Objects inspired this file.

This file inspired Iso 1999:2013, Puma Robot Simulation, Maximize(H Fig), and Subfigure(N Rows,N Cols,Figure Id,Varargin).

MATLAB release MATLAB 7 (R14)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (30)
08 Feb 2017 Rik Wisselink

I think I was referring to a submission that used a .dll, so I must have been confused. I'm now working on a wrapper that tries several methods of maximizing, so I'll include this in the acknowledgements.

You could update the code to:
if nargin < 1
hFig = gcf;
if isa(hFig,'matlab.ui.Figure')
%Convert the figure handle object to a number
drawnow % Required to avoid Java errors
jFig = get(hFig, 'JavaFrame');
pause(0.0001);%give Matlab time to refresh

04 Apr 2016 Oliver Woodford

Rik: Are you referring to a different submission? This function has never been able to do that (though it is straightforward to ad an -all option). Also, it was first submitted in Oct 2009, and there has never been a v4.1.

Comment only
04 Apr 2016 Rik Wisselink

Will there be another version like v4.1 (June 2007)? I liked the option of maximizing all windows without having to save all figure handles in different function scopes.

The problem appeared now that the handle isn't a number anymore, but a handle object. This means that the error described by Jeffrey arises, as num2str doesn't work anymore. Is there an easy way to adapt the code of that version?

PS the warning that it will be obsolete in a future release doesn't bode well, but you can turn it off by using
inside the function

I really like this function, thanks a lot for maintaining it :)

Comment only
24 Sep 2015 Nikolay

Hello. Just after maximize function I want to get the figure position, but I can't:


gives me old position data. Do you know why?

25 Apr 2015 Sushant Hiwale

Works Fine.
This is what I was looking for.
Thanks a lot.

13 Nov 2014 Marcelo Soto Thompson

08 Oct 2014 Oliver Woodford

Jeffrey: Are you using an older version? The current version has only 21 lines, and works in R2014b (albeit throwing a warning).

Comment only
08 Oct 2014 Jeffrey Girard

This worked wonders for me in MATLAB 2014a, but it is currently returning the following error with MATLAB 2014b:

Undefined function 'abs' for input arguments of type 'matlab.ui.Figure'.

Error in num2str (line 66)
xmax = double(max(abs(widthCopy(:))));

Error in maximize (line 137)
windowname = ['maximize_',num2str(h(n))];

Comment only
11 Jan 2014 Peter Nave

10 Dec 2013 Dabbler

Thanks Mathworks, for automatically submitting my rating without allowing me to write a comment first.
Works with Matlab 2013b, but it generates null pointer exceptions when the figure's property 'Visible' is set to off.


10 Dec 2013 Dabbler

10 Dec 2013 Dabbler

10 Dec 2013 Dabbler

01 Dec 2013 Florian

31 Jul 2013 Ben

Ben (view profile)

25 Feb 2013 Sauro Salomoni

Ingenious function. Thank for the author!
Now I need to replace many years of using the ugly set(gcf, 'units', 'normalized', 'outerposition', [0 0 1 1])... :)

25 Feb 2012 dave

dave (view profile)

16 Dec 2011 Joao Henriques

Joao Henriques (view profile)

Works as advertised, thank you!

26 Oct 2011 Lukas

Lukas (view profile)

08 Jun 2011 Julián Francisco

Hi. Your application does not work if the visibility of the figure is off before
calling the mazimize function. I am trying to find a function that maximize the figure window through a smoothed optical transition. Thank you for your attention. Best regards.

15 Jan 2011 Mohammed El-Said

Works great,
Thanks for sharing...

15 Nov 2010 Craig

Craig (view profile)

Worked very nicely for me on Win7 with 64-bit R2010b. I use it together with export_fig to automatically and consitently save high quality figure output.

Many thanks Oliver!

10 Jun 2010 Oliver Woodford

Joris: On the version of MATLAB I have I don't see this error with the latest version of maximize (updated 17th May 2010). Do you have the latest version? It specifically fixed the error you report.

Comment only
10 Jun 2010 JdW

JdW (view profile)

I encounter one issue using your maximize.m function, namely maximize throws exceptions when figure is not yet ready. I include an example:

Example that throws exceptions:
h = figure; maximize(h);

Not so nice looking solution:
h = figure; pause(0.01); maximize(h);

Comment only
18 May 2010 Heinrich Acker

17 May 2010 Heinrich Acker

It's nice to have a real maximize operation without rezising, calling executables or the like. There is one issue, however:

If there is no figure, 'maximize' causes exceptions and makes all subsequent figure or plot operations fail, until the graphic system is sort of reset, e.g. by 'close all'. Tested on R2007b.

Comment only
14 May 2010 JdW

JdW (view profile)

Exactly what I whas looking for. I always did resizing to fill the screen, but this works so much nicer.

21 Apr 2010 Carsten Hoever

19 Apr 2010 Oliver Woodford

Sherif: I've tested this function under several different versions of Matlab and OS's, and it works fine on all of them. If it genuinely doesn't work for you then can I suggest you send me a much more detailed bug report (e.g. Matlab version & OS, error message etc.) via the Contact Author link on my Author page. Posting requests for help here isn't what this comments section is for.

Comment only
18 Apr 2010 Sherif Elnabarawy

i am wondering why all this code and functions for this simple thing , just need to maximize the gui automatically when loading , all codes and functions didn't work perfectly with me , any help ?
thanks a lot,
Sherif Elnabarawy.

13 May 2010 1.1

Removed dependency on jFindobj, using an idea based on comments by Yair Altman on the newsgroup.

17 May 2010 1.2

Fix bug reported by Heinrich Acker (thanks!).

16 Jan 2013 1.3

Acknowledge findjobj.

Contact us