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

3,593 次查看(过去 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 2023-8-28
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.
  2 个评论
MathWorks Support Team
编辑:MathWorks Support Team 2024-2-2
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:

请先登录,再进行评论。

更多回答(6 个)

Antonio Javier Barragán Piña
set(gcf, 'Position', get(0, 'Screensize'));
  3 个评论
Chuck
Chuck 2017-10-18
This one is actually way better than the one verified above. Great job, thanks!
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';
  2 个评论
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.

请先登录,再进行评论。


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:
figure;
pause(0.00001);
frame_h = get(handle(gcf),'JavaFrame');
set(frame_h,'Maximized',1);
  5 个评论
Rik
Rik 2019-11-20
@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.
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.

请先登录,再进行评论。


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
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.

DGM
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.
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 个评论
DGM
DGM 2021-1-3
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
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 2-D and 3-D Plots 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by