File Exchange

image thumbnail


version 1.3 (1.24 KB) by

Platform independent function to maximize a figure window.

22 Ratings



View License

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.

Comments and Ratings (30)

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

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.

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 :)


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?

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

Oliver Woodford

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

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))];

Peter Nave


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.







Ben (view profile)

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])... :)


dave (view profile)

Joao Henriques

Works as advertised, thank you!


Lukas (view profile)

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.

Works great,
Thanks for sharing...


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!

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.


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);

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.


JdW (view profile)

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

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.

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.



Acknowledge findjobj.


Fix bug reported by Heinrich Acker (thanks!).


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

MATLAB Release
MATLAB 7 (R14)

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

» Watch video