有时我们绘图希望figure直接最大化、甚至全屏,虽然用的不多,但是需要用来还真不是一个小问题哦!
(1)最简单的方法就是设置的figure的outerposition或者position属性为screensize,这个方法并非真正的
最大化,只是调整了figure的大小和坐标而已!
-
sz=get(0,'screensize');
-
figure('outerposition',sz);
复制代码
(2)地球人都知道,matlab是使用Java做框架和界面,于是只要从Java入手,应该可以毫无压力的搞定这些
日常操作:
-
h=figure;
-
jFrame=getJFrame(gcf);
%或者jframe=getJFrame(h);
-
jFrame.setMaximized(1); %最大化figure
-
jFrame.setMinimized(1); %最小化figure
-
jFrame.setAlwaysOnTop(1); %将figure置顶
复制代码
需要用掉下面的getJFrame.m代码,具体可以查看这里,另外感谢junziyang编写getJFrame函数!
-
function JFrame = getJFrame(hfig)
-
error(nargchk(1,1,nargin));
-
if ~ishandle(hfig) &&
~isequal(get(hfig,'Type'),'figure')
-
error('The input argument
must be a Figure handle.');
-
end
-
mde = com.MathWorks.mde.desk.MLDesktop.getInstance;
-
if isequal(get(hfig,'NumberTitle'),'off') &&
isempty(get(hfig,'Name'))
-
figTag = 'junziyang'; %Name
the figure temporarily
-
set(hfig,'Name',figTag);
-
elseif isequal(get(hfig,'NumberTitle'),'on') &&
isempty(get(hfig,'Name'))
-
figTag = ['Figure
',num2str(hfig)];
-
elseif isequal(get(hfig,'NumberTitle'),'off') &&
~isempty(get(hfig,'Name'))
-
figTag =
get(hfig,'Name');
-
else
-
figTag = ['Figure
',num2str(hfig),': ',get(hfig,'Name')];
-
end
-
drawnow %Update figure window
-
jfig = mde.getClient(figTag); %Get the underlying JAVA object of
the figure.
-
JFrame = jfig.getRootPane.getParent();
-
if isequal(get(hfig,'Name'),'junziyang')
-
set(hfig,'Name',''); �lete
the temporary figure name
-
end
复制代码
(3)另外在调整figure窗体的位置时,我们可以能需要用到一个movegui()函数,这个函数的功能就是
将figure平移到某个位置,但是不调整figure窗口的大小,具体用法可以参考matlab的帮助。
(4)在Window中Figure无非就是一个窗口,显然我们可以通过Window API对这个窗口进行操作
对应需要调用maximize.m函数以及DLL动态链接库( http://www.matlabsky.com/static/image/filetype/zip.gif maximize.zip (4.21 KB, 下载次数:
60) )
-
function maximize(h)
-
-
% MAXIMIZE maximize figure
windows
-
%
====================================================================
-
%
-
%
Berne
University of Applied Sciences
-
%
-
%
School of
Engineering and Information Technology
-
%
Division of
Electrical- and Communication Engineering
-
%
-
%
====================================================================
-
%
maximize
figure windows
-
%
====================================================================
-
%
-
% Author: Alain
Trostel
-
% e-mail:
alain.trostel@bfh.ch
-
% Date:
June 2007
-
% Version: 4.1
-
%
-
%
====================================================================
-
%
-
% function maximize(h)
-
%
-
% Input parameters
-
% -----------------
-
% h
handle(s)
of the figure window
-
%
-
%
-
% Output parameters
-
% ------------------
-
% The function has no output
parameters.
-
%
-
%
-
% Used files
-
% -----------
-
% -
windowMaximize.dll
-
%
-
%
-
% Examples
-
% ---------
-
% % maximize the current
figure
-
%
------------------------------
-
% maximize;
-
%
-
%
-
% % maximize the current
figure
-
%
------------------------------
-
% maximize(gcf);
-
%
-
%
-
% % maximize the specified
figure
-
%
--------------------------------
-
% h = figure;
-
% maximize(h);
-
%
-
%
-
% % maximize the application
window
-
%
----------------------------------
-
% maximize(0);
-
%
-
%
-
% % maximize more than one
figure
-
%
--------------------------------
-
% h(1) = figure;
-
% h(2) = figure;
-
% maximize(h);
-
%
-
%
-
% % maximize all
figures
-
%
-----------------------
-
% maximize('all');
-
%
-
%
-
% % maximize a GUI in the
OpeningFcn
-
%
-----------------------------------
-
%
-
% % --- Executes just before
untitled is made visible.
-
% function
untitled_OpeningFcn(hObject, eventdata, handles,
varargin)
-
% % This function has no output
args, see OutputFcn.
-
% % hObject
handle to figure
-
% %
eventdata reserved - to be
defined in a future version of MATLAB
-
% % handles
structure with handles and user data (see
GUIDATA)
-
% % varargin
command line arguments to untitled (see
VARARGIN)
-
%
-
% % Choose default command line
output for untitled
-
% handles.output =
hObject;
-
%
-
% % Update handles
structure
-
% guidata(hObject,
handles);
-
%
-
% % UIWAIT makes untitled wait
for user response (see UIRESUME)
-
% %
uiwait(handles.figure1);
-
%
-
% % maximize the GUI
-
%
set(hObject,'Visible','on');
-
% maximize(hObject);
-
-
-
-
% check if dll-file exists
-
if ~exist('windowMaximize.dll','file')
-
error('windowMaximize.dll not
found.');
-
end
-
-
% if no input parameters, get handle of the current
figure
-
if nargin == 0
-
h = gcf;
-
end
-
-
% if one input parameter, check the input parameter
-
if ischar(h)
-
% check the string
-
if strcmpi(h,'all')
-
% get all
figure handles
-
h =
findobj('Type','figure');
-
else
-
% incorrect
string argument
-
error('Argument
must be the correct string.');
-
end
-
else
-
% check each handle
-
for n=1:length(h)
-
% it must be
a handle and of type 'root' or 'figure'
-
if
~ishandle(h(n)) || (~strcmp(get(h(n),'Type'),'root') &&
...
-
~strcmp(get(h(n),'Type'),'figure'))
-
% incorrect
handle
-
error('Argument(s) must be a correct
handle(s).');
-
end
-
end
-
end
-
-
% if handle is not the root
-
if h ~= 0
-
% for each handle
-
for
n=length(h):-1:1
-
% create the
temporary window name
-
windowname =
['maximize_',num2str(h(n))];
-
-
% save
current window name
-
numTitle =
get(h(n),'NumberTitle');
-
figName =
get(h(n),'Name');
-
-
% set the
temporary window name
-
set(h(n),'Name',windowname,'NumberTitle','off');
-
-
% draw figure
now
-
drawnow;
-
% maximize
the window with the C function
-
windowMaximize(windowname,get(h(n),'Resize'));
-
-
% reset the
window name
-
set(h(n),'Name',figName,'NumberTitle',numTitle);
-
end
-
else
-
% maximize the application
window "MATLAB"
-
windowMaximize('MATLAB');
-
end
复制代码
(5)这里还有一个通过API函数实现的Figure操作, http://www.matlabsky.com/static/image/filetype/zip.gif AlterWindow.zip (1.54 KB, 下载次数:
19)
MEX-file to affect windows, e.g. maximize, minimize, hide, show,
etc.
To compile use
>> mex AlterWindow.c user32.
See AlterWindow.m for help and a list of actions that can be
performed.
|