MATLABでいくつかのFigureを作成し、それらを自動的にファイルに保存しています。定義上、画像が小さいという問題。私の問題を手作業で解決する良い方法は、画像(図)を作成し、それを最大化し、ファイルに保存することです。
図を自動的に最大化するこのステップがありません。
助言がありますか?今まで私はこれを見つけました:
http://answers.yahoo.com/question/index?qid=20071127135551AAR5JYh
http://www.mathworks.com/matlabcentral/newsreader/view_thread/238699
しかし、誰も私の問題を解決していません。
これは私のために働いた:
figure('units','normalized','outerposition',[0 0 1 1])
または現在の図の場合:
set(gcf,'units','normalized','outerposition',[0 0 1 1])
また、Javaを使用するFileExchangeで [〜#〜] maximize [〜#〜] 関数を使用しました。これが真の最大化です。
実際の最大化の場合(OS XおよびWindowsのUIで最大化ボタンをクリックするのとまったく同じように)、非表示のJavaハンドルを呼び出す
_figure;
pause(0.00001);
frame_h = get(handle(gcf),'JavaFrame');
set(frame_h,'Maximized',1);
_
pause(n)
は、上記がMatlab scapeから出て、別のJavaスレッド。任意の値にn
を設定し、チェックする結果:実行時のコンピューターの速度が速いほど、n
は小さくなります。
完全な「ドキュメント」を見つけることができます こちら
R2018a現在 、figure
およびuifigure
オブジェクトには、WindowState
というプロパティが含まれています。これはデフォルトで'normal'
に設定されていますが、'maximized'
に設定すると目的の結果が得られます。
結論として:
hFig.WindowState = 'maximized'; % Requires R2018a
ところで、元の問題に対処するために-結果が小さすぎることを心配せずに図の内容を画像にエクスポートしたい場合は、 export_fig
ユーティリティを強くお勧めします。
図を最大化するには、実際に使用するキーのシーケンスを模倣できます。
キーをプログラムで送信するには、次のように this answer に似たJavaベースの手順を使用できます。
h = figure; %// create figure and get handle
plot(1:10); %// do stuff with your figure
figure(h) %// make it the current figure
robot = Java.awt.Robot;
robot.keyPress(Java.awt.event.KeyEvent.VK_ALT); %// send ALT
robot.keyPress(Java.awt.event.KeyEvent.VK_SPACE); %// send SPACE
robot.keyRelease(Java.awt.event.KeyEvent.VK_SPACE); %// release SPACE
robot.keyRelease(Java.awt.event.KeyEvent.VK_ALT); %// release ALT
robot.keyPress(Java.awt.event.KeyEvent.VK_X); %// send X
robot.keyRelease(Java.awt.event.KeyEvent.VK_X); %// release X
ほら!ウィンドウが最大化されました!
上記の著者によって提案されたように 、「最大化」ウィンドウボタンをクリックすることをシミュレートしたい場合、続くコード。言及された答えとの違いは、「一時停止」の代わりに「drawnow」を使用する方がより正しいように見えることです。
figure;
% do your job here
drawnow;
set(get(handle(gcf),'JavaFrame'),'Maximized',1);
図ウィンドウを最大化することは、図を高解像度のイメージとして保存する最良の方法ではありません。
印刷と保存 のFigureプロパティがあります。これらのプロパティを使用すると、任意の解像度でファイルを保存できます。ファイルを保存するには、dpi
値を設定できるため、 print function を使用する必要があります。そのため、最初に次のFigureプロパティを設定します。
set(FigureHandle, ...
'PaperPositionMode', 'manual', ...
'PaperUnits', 'inches', ...
'PaperPosition', [0 0 Width Height])
次に、ファイルを(たとえば)100dpiのpngとして保存します('-r100'
)
print(FigureHandle, Filename, '-dpng', '-r100');
100dpiで保存するため、2048x1536px
でファイルを取得するには、Width = 2048/100
およびHeight 1536/100
、/100
を設定します。 dpi値を変更する場合は、除数も同じ値に変更する必要があります。
ご覧のとおり、ファイル交換やJavaベースの手順からの追加機能は必要ありません。さらに、任意の解像度を選択できます。
これを試すことができます:
screen_size = get(0, 'ScreenSize');
f1 = figure(1);
set(f1, 'Position', [0 0 screen_size(3) screen_size(4) ] );
%% maximizeFigure
%
% Maximizes the current figure or creates a new figure. maximizeFigure() simply maximizes the
% current or a specific figure
% |h = maximizeFigure();| can be directly used instead of |h = figure();|
%
% *Examples*
%
% * |maximizeFigure(); % maximizes the current figure or creates a new figure|
% * |maximizeFigure('all'); % maximizes all opened figures|
% * |maximizeFigure(hf); % maximizes the figure with the handle hf|
% * |maximizeFigure('new', 'Name', 'My newly created figure', 'Color', [.3 .3 .3]);|
% * |hf = maximizeFigure(...); % returns the (i.e. new) figure handle as an output|
%
% *Acknowledgements*
%
% * Big thanks goes out to Yair Altman from http://www.undocumentedmatlab.com/
%
% *See Also*
%
% * |figure()|
% * |gcf()|
%
% *Authors*
%
% * Daniel Kellner, medPhoton GmbH, Salzburg, Austria, 2015-2017
%%
function varargout = maximizeFigure(varargin)
warning('off', 'MATLAB:HandleGraphics:ObsoletedProperty:JavaFrame')
% Check input variables
if isempty(varargin)
hf = gcf; % use current figure
elseif strcmp(varargin{1}, 'new')
hf = figure(varargin{2:end});
elseif strcmp(varargin{1}, 'all')
hf = findobj('Type', 'figure');
elseif ~isa(varargin{1}, 'char') && ishandle(varargin{1}) &&...
strcmp(get(varargin{1}, 'Type'), 'figure')
hf = varargin{1};
else
error('maximizeFigure:InvalidHandle', 'Failed to find a valid figure handle!')
end
for cHandle = 1:length(hf)
% Skip invalid handles and plotbrowser handles
if ~ishandle(cHandle) || strcmp(get(hf, 'WindowStyle'), 'docked')
continue
end
% Carry the current resize property and set (temporarily) to 'on'
oldResizeStatus = get(hf(cHandle), 'Resize');
set(hf(cHandle), 'Resize', 'on');
% Usage of the undocumented 'JavaFrame' property as described at:
% http://undocumentedmatlab.com/blog/minimize-maximize-figure-window/
jFrame = get(handle(hf(cHandle)), 'JavaFrame');
% Due to an Event Dispatch thread, the pause is neccessary as described at:
% http://undocumentedmatlab.com/blog/matlab-and-the-event-dispatch-thread-edt/
pause(0.05)
% Don't maximize if the window is docked (e.g. for plottools)
if strcmp(get(cHandle, 'WindowStyle'), 'docked')
continue
end
% Don't maximize if the figure is already maximized
if jFrame.isMaximized
continue
end
% Unfortunately, if it is invisible, it can't be maximized with the Java framework, because a
% null pointer exception is raised (Java.lang.NullPointerException). Instead, we maximize it the
% straight way so that we do not end up in small sized plot exports.
if strcmp(get(hf, 'Visible'), 'off')
set(hf, 'Units', 'normalized', 'OuterPosition', [0 0 1 1])
continue
end
jFrame.setMaximized(true);
% If 'Resize' will be reactivated, MATLAB moves the figure slightly over the screen borders.
if strcmp(oldResizeStatus, 'off')
pause(0.05)
set(hf, 'Resize', oldResizeStatus)
end
end
if nargout
varargout{1} = hf;
end
これは最も短い形式です
figure('Position',get(0,'ScreenSize'))