Asked by MathWorks Support Team
on 21 Oct 2013

I would like to maximize, minimize or restore my figure programmatically in MATLAB.

Answer by MathWorks Support Team
on 31 Oct 2017

Accepted Answer

There is currently no built-in functionality to maximize, minimize or get the state of a figure in MATLAB.

As a workaround for MATLAB 7.4 (R2007a) and later versions, the attached files maxfig.p, minfig.p and figstate.p (with help files maxfig.m, minfig.m and figstate.m) allow you to perform these actions as follows:

minfig(F,1) % Minimizes the figure window for the figure with handle F

minfig(F,0) % Restores figure F if F is minimized

maxfig(F,1) % Maximizes the figure window for the figure with handle F

maxfig(F,0) % Restores figure F if F is maximized

s = figstate(F) % Returns the state of figure { Maximized | Minimized | Normal }

Please note that querying the figure position immediately after using these functions may not work reliably unless the figure resize is complete.

There are no workarounds for versions prior to MATLAB 7.4 (R2007a).

Answer by Jan
on 27 Sep 2014

Edited by Jan
on 28 Mar 2018

In reply to Max Müller's comment: I'm not sure if this works under 2006a already, but it fails under R6.5:

jFrame = get(handle(FigureHandle), 'JavaFrame');

jFrame.setMaximized(1);

Other useful methods:

jFrame.setMaximized(0);

jFrame.setMinimized(1);

jFrame.isMaximized % Thanks Image Analyst

jFrame.isMinimized

Jan
on 28 Sep 2014

:-) Guess it.

Lennart van Luijk
on 20 Aug 2015

ori yungrise
on 17 Oct 2018

Sign in to comment.

Answer by Nikolay S.
on 14 May 2015

Edited by Nikolay S.
on 14 May 2015

Answer by Conrad Andrews
on 15 Jun 2017

Potentially a solution that may help:

If you get the figure handle and find the position property for that figure, it can give you the exact location and size of the figure on your screen. Say for example if you want to save the figure automatically at a particular window size.

Figgy = gcf;

Figgy.Position

This returned:

ans =

2 42 958 954

Which is where I set my figure at on the screen with the exact window size I wanted. Now if I want to replicate this position for a second figure (to save it with the exact size), I get the figure handle for the second one but this time I set the Position value to those coordinates:

Figgy2 = gcf;

Figgy2.Position = [2, 42, 958, 954];

Then my new figure is in the exact size and location as my previous one. I hope this helps someone.

Sign in to comment.

Opportunities for recent engineering grads.

Apply Today
## 7 Comments

## Avi (view profile)

## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/98331-is-it-possible-to-maximize-minimize-or-get-the-state-of-my-figure-programmatically-in-matlab#comment_211408

## Max Müller (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/98331-is-it-possible-to-maximize-minimize-or-get-the-state-of-my-figure-programmatically-in-matlab#comment_239652

## Image Analyst (view profile)

## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/98331-is-it-possible-to-maximize-minimize-or-get-the-state-of-my-figure-programmatically-in-matlab#comment_239670

## Matt J (view profile)

## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/98331-is-it-possible-to-maximize-minimize-or-get-the-state-of-my-figure-programmatically-in-matlab#comment_267296

## Steve Grobler (view profile)

## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/98331-is-it-possible-to-maximize-minimize-or-get-the-state-of-my-figure-programmatically-in-matlab#comment_421720

## Steven Lord (view profile)

## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/98331-is-it-possible-to-maximize-minimize-or-get-the-state-of-my-figure-programmatically-in-matlab#comment_545855

## Matt J (view profile)

## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/98331-is-it-possible-to-maximize-minimize-or-get-the-state-of-my-figure-programmatically-in-matlab#comment_546326

Sign in to comment.