# How to make a figure fit a screen on a 2nd monitor?

조회 수: 74 (최근 30일)
DrKarimKecir 2017년 7월 21일
댓글: Rik 2019년 6월 28일
Hi,
I have a laptop connected to an external monitor which I exclusively use (laptop monitor is turned off) and I would like to fit a MATLAB figure to my monitor screen with:
figure('outerposition',get(0,'screensize')); % or 'monitorpositions'
but it only fits part of the screen. This external screen does not use the same resolution as the one used on the laptop screen (the external monitor's is bigger) and I can't find a method to make the figure fit the external monitor's screen. I tried things such as:
figure('units','normalized','outerposition',[0 0 1 1.2]);
without success. Any help would be greatly appreciated as I'm out of ideas.
KK

댓글을 달려면 로그인하십시오.

### 답변 (2개)

Dominik Mattioli 2019년 6월 28일
편집: Dominik Mattioli 2019년 6월 28일
I've found that setting the outerPosition property can be awkward, especially with a taskbar in the mix.
% Get pixel position of monitors.
fh = figure('units', 'pixels');
MP = get(0, 'MonitorPositions');
N = size(MP, 1);
% Might want to set an initial position this to some reasonable location
% in the event of the window being "Restored Down".
newPosition = MP(1,:)
% dFromLeftRight = 0.125*MP(N, 3);
% dFromTopBottom = 0.125*MP(N, 4);
% newPosition = [MP(N,1)+dFromLeftRight,...
% MP(N,2)+dFromTopBottom,...
% MP(N,3)-(dFromLeftRight*2),...
% MP(N,4)-(dFromTopBottom*2)];
% Set position of fh to be within a secondary monitor, if possible.
if size(MP, 1) == 1
% Single monitor -- do nothing.
else
% Multiple monitors - shift to the Nth monitor.
newPosition(1) = newPosition(1) + MP(N,1);
end
fh.set('Position', newPosition, 'units', 'normalized');
fh.WindowState = 'maximized'; % Maximize with respect to current monitor.
The newPosition variable just makes sure the figure is first in your desired monitor before you maximize the window. Ideally, you could get the position of your MATLAB editor window and simply index N to be anything but that window so that your figure maximizes in a different one. Haven't figured that out yet.
Not sure if/how this works on non-Windows computers.
##### 댓글 수: 1이전 댓글 -1개 표시이전 댓글 -1개 숨기기
Rik 2019년 6월 28일
On releases without the WindowState option, you can use this function instead to maximize your figure.

댓글을 달려면 로그인하십시오.

ANKUR KUMAR 2017년 12월 2일
figure('units','normalized','outerposition',[0 0 1 1]);
Last value should be less than 1. You have entered 1.2 You are setting units as normalized. This means that you are changing the monitor dimension in between 0 and 1. 0 is minimum and 1 is maximum.
##### 댓글 수: 1이전 댓글 -1개 표시이전 댓글 -1개 숨기기
DrKarimKecir 2017년 12월 2일
Hello Ankur Kumar,
What you say is logical, but for some reason when I input [0 0 1 1] it fills only part of the external monitor screen and not the full screen. It might have to do with the fact that the width/height proportions on the screens are not the same.

댓글을 달려면 로그인하십시오.

### 카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

### Community Treasure Hunt

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

Start Hunting!

Translated by