MATLAB Answers

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

4,046 ビュー (過去 30 日間)
MathWorks Support Team
MathWorks Support Team 2009 年 6 月 27 日
コメント済み: Rik 2021 年 1 月 3 日 21:47
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 件のコメント

表示 1 件の古いコメント
Elias Gule
Elias Gule 2015 年 3 月 24 日
I hope this helps:
hFig = figure('Name','25');
Nikolay S.
Nikolay S. 2015 年 5 月 14 日
My function Minimize/maximize figure window does this.
MathWorks Support Team
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:

サインインしてコメントする。

その他の回答 (8 件)

Antonio Javier Barragán Piña
Antonio Javier Barragán Piña 2016 年 6 月 6 日
set(gcf, 'Position', get(0, 'Screensize'));

  5 件のコメント

表示 2 件の古いコメント
Chuck
Chuck 2017 年 10 月 18 日
This one is actually way better than the one verified above. Great job, thanks!
Zahid Ashraf
Zahid Ashraf 2020 年 1 月 16 日
where do I place this code in the editor?
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.

サインインしてコメントする。


Bogdan Dzyubak
Bogdan Dzyubak 2016 年 8 月 16 日
編集済み: Bogdan Dzyubak 2016 年 8 月 16 日
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);

  9 件のコメント

表示 6 件の古いコメント
John McDowell
John McDowell 2020 年 10 月 17 日
As @Walter Roberson notes, JavaFrame will be removed in future releases. Inspired by @Bogdan's and @Antonio's answers, I went with:
set(gcf,'WindowState','Maximized')
Insert this after a figure has been created, and it will maxmise, but will keep the taskbar in view. Can also be run in the command window to make the last figure interacted with maximised.
Rik
Rik 2020 年 10 月 17 日
You can use some code that checks what solution is supported by the release. That way you can ensure the function keeps working for releases that only support one or the other. Like this.
gaoyi guo
gaoyi guo 2020 年 10 月 23 日
This may be the best solution, the figure window is maximized to the real screen size!

サインインしてコメントする。


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 件のコメント

表示 4 件の古いコメント
Dominik Mattioli
Dominik Mattioli 2020 年 1 月 16 日
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
Steven Lord 2020 年 1 月 16 日
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
Richard Hall 2020 年 2 月 21 日
This solution works well.

サインインしてコメントする。


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.

  0 件のコメント

サインインしてコメントする。


Jan
Jan 2018 年 2 月 26 日
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 件のコメント

サインインしてコメントする。


WCJHunter
WCJHunter 2019 年 1 月 27 日
As steven lord above said:
set(gcf,'WindowState','fullscreen')

  0 件のコメント

サインインしてコメントする。


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
DGM 2020 年 12 月 31 日 16:47
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.
windowname='AUTOPLOTTER';
set(myfigurehandle,'numbertitle','off','name',windowname)
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 件のコメント

表示 2 件の古いコメント
Rik
Rik 2021 年 1 月 1 日 16:34
You claim this code is version agnostic. What kind of complaints would you be inviting? I haven't had any complaints in my function (the function I linked). I might include your code in a future version, but it has fairly low priority, as releases without the Java frame will have the window state property. That means my function is guaranteed to work. Code like yours might be required for Octave.
DGM
DGM 2021 年 1 月 3 日 18:04
I said it should be (Matlab) version-agnostic. I've only used it on a handful of versions, and nothing particularly new, so I can't guarantee that. I kind of expect that's the default unspoken disclaimer for Matlab code, especially as graphics stuff evolves.
The primary issue is that it's not platform-agnostic. It's not going to work on Windows or if wmctrl isn't installed. That probably means that the majority of users can't use this simplified code out of the box, and I don't feel like relying on everyone to read the FEX description before they download it and get disappointed. If someone else is in a better position to use it as a special case alongside code suited for newer versions or other platforms, I'll leave it to them.
I didn't say it was ideal. It's probably slower than anything else. It's just what I use in my own scripts for generating documentation. I have a habit of using the bludgeon of tools like wmctrl to solve problems when other apps have no means to behave as I expect, so maybe I tend to overuse it out of mere familiarity.
Rik
Rik 2021 年 1 月 3 日 21:47
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.

サインインしてコメントする。

カテゴリ

Community Treasure Hunt

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

Start Hunting!

Translated by