37

MATLAB でいくつかの Figure を作成しており、それらを自動的にファイルに保存しています。定義上、画像が小さいという問題。私の問題を手作業で解決する良い方法は、画像 (図) を作成し、最大化し、ファイルに保存することです。

フィギュアを自動的に最大化するこのステップがありません。

助言がありますか?今まで私はこれしか見つけられませんでした:

http://answers.yahoo.com/question/index?qid=20071127135551AAR5JYh

http://www.mathworks.com/matlabcentral/newsreader/view_thread/238699

しかし、誰も私の問題を解決していません。

4

10 に答える 10

61

これは私のために働いた:

figure('units','normalized','outerposition',[0 0 1 1])

または現在の図の場合:

set(gcf,'units','normalized','outerposition',[0 0 1 1])

Javaを使用するFileExchangeでMAXIMIZE関数も使用しました。これが真の最大化です。

于 2013-03-08T05:12:40.857 に答える
6

数値を最大化するには、実際に使用するキーのシーケンスを模倣できます。

  1. ALT- (ここSPACEに示されているように) ウィンドウ メニューにアクセスします。その後
  2. X最大化します (これはシステムによって異なる場合があります)。

キーをプログラムで送信するには、次のように、この回答に似た 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

ほら!ウィンドウが最大化されました!

于 2015-07-07T23:19:48.537 に答える
4

上記の著者によって提案されているように、「ウィンドウを最大化」ボタンのクリックをシミュレートしたい場合は、次のコードを使用できます。言及された答えとの違いは、「一時停止」の代わりに「ドローダウン」を使用する方が正しいように見えることです。

figure;
% do your job here
drawnow;
set(get(handle(gcf),'JavaFrame'),'Maximized',1);
于 2015-06-08T08:49:37.027 に答える
4

Figureウィンドウを最大化することは、Figureをより高い解像度の画像として保存するための最良の方法ではありません。

印刷および保存用の Figure プロパティがあります。これらのプロパティを使用すると、必要な解像度でファイルを保存できます。ファイルを保存するには、値を設定できるため、 print 関数dpiを使用する必要があります。したがって、最初に次の Figure プロパティを設定します。

set(FigureHandle, ...
    'PaperPositionMode', 'manual', ...
    'PaperUnits', 'inches', ...
    'PaperPosition', [0 0 Width Height])

次に、ファイルを(たとえば)100dpiのpngとして保存します('-r100'

print(FigureHandle, Filename, '-dpng', '-r100');

100dpi で保存するので、 2048x1536pxsetWidth = 2048/100と Height1536/100でファイルを取得します。/100dpi 値を変更する場合は、除数も同じ値に変更する必要があります。

ご覧のとおり、ファイル交換や Java ベースの手順による追加機能は必要ありません。さらに、任意の解像度を選択できます。

于 2016-03-11T09:51:22.297 に答える
2

あなたはこれを試すことができます:

screen_size = get(0, 'ScreenSize');
f1 = figure(1);
set(f1, 'Position', [0 0 screen_size(3) screen_size(4) ] );
于 2013-12-24T09:25:00.037 に答える
1
%% 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
于 2017-08-31T12:04:16.627 に答える
0

これが最短の形です

figure('Position',get(0,'ScreenSize'))
于 2015-01-14T11:17:31.880 に答える