# How do I make a figure full screen programmatically in MATLAB?

조회 수: 6,179(최근 30일)
댓글: Richard Hall 21 Feb 2020 8:54
I would like to make my figure "full screen" without using the mouse to maximize the figure window.

### 채택된 답변

To make a figure the same size as your screen in MATLAB execute the following command:
figure('units','normalized','outerposition',[0 0 1 1])
Please also see the related solution below for a method of programmatically maximizing, minimizing, and restoring a figure window.

#### 댓글 수: 3

Ben 24 Mar 2015
How do I name that figure some number like I do when I write "figure(2)", "figure(3)", etc.? When I use this command, it just makes this figure the next number in line.
Elias Gule 24 Mar 2015
I hope this helps:
hFig = figure('Name','25');
Nikolay S. 14 May 2015
My function Minimize/maximize figure window does this.

로그인 to comment.

### 추가 답변(7개)

set(gcf, 'Position', get(0, 'Screensize'));

#### 댓글 수: 5

표시 이전 댓글 수: 2
Chuck 18 Oct 2017
This one is actually way better than the one verified above. Great job, thanks!
Zahid Ashraf 16 Jan 2020
where do I place this code in the editor?
Walter Roberson 16 Jan 2020
You would put it in the code at the point at which you want to force the figure to full screen.
If you want to do it for a GUIDE GUI then you can put it in the *OpenFcn callback code.

로그인 to comment.

Bogdan Dzyubak 16 Aug 2016
편집: Bogdan Dzyubak 16 Aug 2016
The proposed methods are simple but make the figure "nearly" full screen which can cause you to close the maximized Matlab session instead of the figure.
For actual maximize you can use the following:
figure;
pause(0.00001);
frame_h = get(handle(gcf),'JavaFrame');
set(frame_h,'Maximized',1);

#### 댓글 수: 6

표시 이전 댓글 수: 3
Steven Lord 20 Nov 2019
Rik, if you don't need to support releases earlier than release R2007a in your code you can check using verLessThan instead of using a try / catch block.
Rik 20 Nov 2019
@Steven, that's a good suggestion.
Meanwhile me and other loonies that want compatibility with ML6.5 and GNU Octave need to use spaghetti code like this.
it's a good way for gui...just copy this code in OutputFcn of your gui
#maximize gui

로그인 to comment.

Dominik Mattioli 20 Jun 2019
편집: Dominik Mattioli 20 Jun 2019
If you want to account for the taskbar (I found this in the comments of some other question):
fh = figure();
fh.WindowState = 'maximized';

#### 댓글 수: 7

표시 이전 댓글 수: 4
Dominik Mattioli 16 Jan 2020
Not sure what you mean without seeing any code. As long as you’re not reassigning the variable for the specific figure’s handle (fh) in your for loop, this solution should always work.
Steven Lord 16 Jan 2020
If you're creating many figure objects in a loop and want them all to be maximized, you could set that property at creation.
fh = figure('WindowState', 'maximized')
Most if not all settable properties of Handle Graphics objects can be set this way, though sometimes (mainly for properties that interact like Units and Position) you may need to be careful about your input argument ordering.
Richard Hall 21 Feb 2020 8:54
This solution works well.

로그인 to comment.

Steven Lord 26 Apr 2018
It is possible to do this as of release R2018a using the WindowState property of a figure object.

#### 댓글 수: 0

로그인 to comment.

Jan 26 Feb 2018
Under Windows you can use the API of the OS, see https://www.mathworks.com/matlabcentral/fileexchange/31437-windowapi :
FigH = figure;
WindowAPI(FigH, 'full'); % fill the current monitor
WindowAPI(FigH, 'work'); % fill the current monitor without taskbar, if there is one
No window border anymore, just the inner position.

#### 댓글 수: 0

로그인 to comment.

WCJHunter 27 Jan 2019
As steven lord above said:
set(gcf,'WindowState','fullscreen')

#### 댓글 수: 0

로그인 to comment.

Martin Leo 21 Mar 2019
편집: Martin Leo 21 Mar 2019
To open a fullscreen figure window in MATLAB, use the "Position" option of the figure command. There are two way:
1. Get the screen size and give it to figure:
s = get(0, 'ScreenSize');
figure('Position', [0 0 s(3) s(4)]);
2. Without bothering to get the screen size, use normalized units:
figure('Units','normalized','Position',[0 0 1 1])

#### 댓글 수: 1

Walter Roberson 21 Mar 2019
This will give you "full screen except for the title bar or dock or bottom bar". You need other techniques for true full screen.

로그인 to comment.

이 질문에 답변하려면 로그인을(를) 수행하십시오.

Translated by