This function maximizes MATLAB figures on any platform, and any version of MATLAB at least as far back as 7.0 (possibly further). It takes a figure handle as input. Note: it doesn't simply resize the figure to fill the screen.
showing error while running code...
There is no WindowStyle property on the Image class.
Error in maximize (line 25)
set(hFig, 'WindowStyle', 'normal');
This seems to work great, except for the warning message introduced below.
@Maxime and @All
the warning message can be temporarily suppressed by the line below. This should be combined with a version check to make the script more solid. For that matter a proper check since which Matlab version the warning occurs would be nice! Can somebody please validate that?! :)
if ~verLessThan('Matlab','9.2') % maybe since Matlab R2017a
The function works great. But Matlab warns that javaframe will be obsolete in future releases. This clogs my command window as I run the maximize function three times for the current script. Running 2017b.
" Warning: figure JavaFrame property will be obsoleted in a future release. For more information see the
JavaFrame resource on the MathWorks web site. "
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;
%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
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.
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?
This is what I was looking for.
Thanks a lot.
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))];
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.
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])... :)
Works as advertised, thank you!
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.
Thanks for sharing...
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!
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.
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.
Exactly what I whas looking for. I always did resizing to fill the screen, but this works so much nicer.
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,
Adds support for R2018a's Java-less WindowState property
Suppress JavaFrame obsoletion message
Fix bug reported by Heinrich Acker (thanks!).
Removed dependency on jFindobj, using an idea based on comments by Yair Altman on the newsgroup.
Create scripts with code, output, and formatted text in a single executable document.