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

조회 수: 4,997(최근 30일)
I would like to make my figure "full screen" without using the mouse to maximize the figure window.

채택된 답변

MathWorks Support Team
MathWorks Support Team 2020년 12월 2일
편집: MathWorks Support Team 2020년 12월 2일
Starting in MATLAB R2018a, you can use the WindowState property to maximize, minimize, or display a figure in full-screen mode.
To make a figure the same size as your screen in previous releases, you may use this 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.
  댓글 수: 4
MathWorks Support Team
MathWorks Support Team 2020년 11월 4일
편집: MathWorks Support Team 2020년 11월 4일
Starting in MATLAB R2018a, you can use the "WindowState" property to maximize, minimize, or display a figure in full-screen mode. Please refer to the following documentation for more information:

댓글을 달려면 로그인하십시오.

추가 답변(9개)

Antonio Javier Barragán Piña
Antonio Javier Barragán Piña 2016년 6월 6일
set(gcf, 'Position', get(0, 'Screensize'));
  댓글 수: 5
Walter Roberson
Walter Roberson 2020년 1월 16일
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.

댓글을 달려면 로그인하십시오.

Dominik Mattioli
Dominik Mattioli 2019년 6월 20일
편집: Dominik Mattioli 2019년 6월 20일
If you want to account for the taskbar (I found this in the comments of some other question):
fh = figure();
fh.WindowState = 'maximized';
  댓글 수: 7
Richard Hall
Richard Hall 2020년 2월 21일
This solution works well.

댓글을 달려면 로그인하십시오.

Bogdan Dzyubak
Bogdan Dzyubak 2016년 8월 16일
편집: MathWorks Support Team 2021년 6월 24일
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:
frame_h = get(handle(gcf),'JavaFrame');
  댓글 수: 9
gaoyi guo
gaoyi guo 2020년 10월 23일
This may be the best solution, the figure window is maximized to the real screen size!

댓글을 달려면 로그인하십시오.

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

Jan 2018년 2월 26일
Under Windows you can use the API of the OS, see :
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.

WCJHunter 2019년 1월 27일
As steven lord above said:

Martin Leo
Martin Leo 2019년 3월 21일
편집: Martin Leo 2019년 3월 21일
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
Walter Roberson 2019년 3월 21일
This will give you "full screen except for the title bar or dock or bottom bar". You need other techniques for true full screen.

댓글을 달려면 로그인하십시오.

DGM 2020년 12월 31일
Similar to Jan's answer, it's possible to use system-level tools to maximize windows in Linux. That way, the behavior should be version-agnostic and will resize the window to the geometry that you'd expect if you just clicked the window maximize button manually.
In order to identify the window externally, simply give the figure window an unambiguous title. Then you can just use wmctrl to fetch the windowid and subsequently maximize the window.
pause(1) % wait for the window manager
system(sprintf('winid=$(wmctrl -lx | grep "%s" | cut -d \\ -f 1 | tail -n 1); wmctrl -ir "$winid" -b add,maximized_vert,maximized_horz',windowname))
  댓글 수: 5
Rik 2021년 1월 3일
There are plenty of submissions that sound like they have implemented some revolutionary idea, all while simply setting the Position to the screensize. Looking at the comments in Jan's submission I don't see anyone complaining that it only works on Windows. As long as your description clearly states this requirement, I don't see why it doesn't deserve a FEX page. The chance that it will be found by prospective users here is much smaller.
Do you have a way of programatically checking if wmctrl is working as expected? If so, you could even implement a check (along with isunix&&~ismac) and issue an error. In my humble opinion you shouldn't worry about people who don't bother to read the first two lines of your description.
If I ever decide to implement this, I will put a link to this answer in the comments of the code. If you ever do decide to post this to the FEX I can credit the FEX entry instead.

댓글을 달려면 로그인하십시오.

ahmadreza keihani
ahmadreza keihani 2021년 5월 27일
H = gcf;% or H=gca
H.WindowState = 'maximized';
saveas(gcf,filename, 'jpg') % Or savefig(filename)
  댓글 수: 3
Rik 2021년 5월 27일
I admit Steven's answer is less direct than yours, but this answer does the exact same thing. It even uses a separately stored handle as well. I don't really see why using specifically gcf would merit a new answer.
I also don't see what saveas has to do with this question. I agree that it is a useful function, but there are hunderds of important and useful functions people might not know. I think threads like these should stay focussed and only provide solutions for the problem at hand, leaving other threads to deal with the question of how to save a figure to an image file.

댓글을 달려면 로그인하십시오.


Find more on 2-D and 3-D Plots in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by