Is it possible to viewing the "figure" window on second display?
182 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Dmitriy Shaulskiy
el 24 de Sept. de 2011
Comentada: Guillaume Baptist
el 14 de Jul. de 2022
I have two displays connected to my PC. Is it possible to define which of to displays will be viewed "figure" window?
0 comentarios
Respuesta aceptada
Jan
el 25 de Sept. de 2011
Editada: Jan
el 2 de Sept. de 2020
You could create a function, which open figures on the 2nd monitor if it is available, otherwise the 1st monitor is used:
% [EDITED, 2018-06-05, typos fixed]
function FigHandle = figure2(varargin)
MP = get(0, 'MonitorPositions');
if size(MP, 1) == 1 % Single monitor
FigH = figure(varargin{:});
else % Multiple monitors
% Catch creation of figure with disabled visibility:
indexVisible = find(strncmpi(varargin(1:2:end), 'Vis', 3));
if ~isempty(indexVisible)
paramVisible = varargin(indexVisible(end) + 1);
else
paramVisible = get(0, 'DefaultFigureVisible');
end
%
Shift = MP(2, 1:2);
FigH = figure(varargin{:}, 'Visible', 'off');
drawnow;
set(FigH, 'Units', 'pixels');
pos = get(FigH, 'Position');
pause(0.02); % See Stefan Glasauer's comment
set(FigH, 'Position', [pos(1:2) + Shift, pos(3:4)], ...
'Visible', paramVisible);
end
if nargout ~= 0
FigHandle = FigH;
end
17 comentarios
Walter Roberson
el 3 de Sept. de 2021
https://www.mathworks.com/help/matlab/ref/varargin.html
varargin allows you to receive a variable number of function arguments by using cell array syntax.
Más respuestas (3)
the cyclist
el 24 de Sept. de 2011
Yes, effectively. One way to do it is by defining the 'Position' property of the figure. If you create your figure, then type
>> get(gcf)
You will see the current properties of the figure, including the Position property. You can then set that position to be whatever you want, e.g.
>> set(gcf,'Position',[500 500 400 300])
The arrangement of your second display will determine where you need to "push" the figure to. For example, with my setup, I actually had to make the x-position (first value in the vector) a negative value to push it onto my second display.
2 comentarios
Jonatan Dias
el 25 de Sept. de 2017
Hi.
Thank you very much for your answer.
Extremely easy!
Regards, Jonatan.
Guillaume Baptist
el 14 de Jul. de 2022
Thanks, it perfectly works for me too. Very easy.
Cheers,
Guillaume
thalia
el 17 de Sept. de 2019
Editada: dpb
el 28 de Feb. de 2022
Simplifying Adan's script...
close all
f=figure('Units','normalized')
%place it wherever you want in the 1st monitor
f
%check units
%retreive location info
pos1 = f.Position
close all
f=figure('Units','normalized')
%place it wherever you want in the 1st monitor
pos2 = f.Position
close all
%Evaluate the following code or add it in the startup.m for permanent settings
%in case you want to add it permanently, replace the pos1,2 with the values (hard-coded)
MP = get(0, 'MonitorPositions');
if size(MP, 1) == 1 % 1 monitor
set(0, 'defaultFigureUnits', 'normalized','defaultFigurePosition', pos1)
else %2nd monitor
set(0, 'defaultFigureUnits', 'normalized','defaultFigurePosition', pos2)
end
0 comentarios
Walter Roberson
el 24 de Sept. de 2011
Take your pick of answers:
- Yes, but you would not like the result; OR
- No, but you can make it work fairly well
The respective methods:
1. set(0,'DefaultFigurePosition', [x y w h])
where x, y, w, and h are fixed x and y coordinates and w and h are fixed width and height. You can work out the coordinates to use by examining
get(0,'MonitorPositions')
The reason you probably wouldn't like this is that all figures will appear at that exact position and size (on top of whatever was there before) unless the code overrides the position. And there are a bunch of things that are actually figures. Including all GUI elements and including all dialog boxes.
2. Instead of setting the default figure position for everything, either right when you create the figure or right afterwards, set its Position property to be where you want it (and the size you want) on the second monitor, having used the MonitorPositions root property to find the proper range.
Warning Either way, it is not possible to getframe() a figure that is on the second monitor. This may affect your ability to saveas() or print(). Some routines detect the situation and temporarily move the figure on to the main screen and move it back afterwards, but other routines just complain.
5 comentarios
Daniel Shub
el 25 de Sept. de 2011
hgrc is called by matlabrc. You are correct that it doesn't appear documented. My figures, both in Linux and Windows appear on top of each other in the exact position and size. Most dialog boxes, and I cannot think of any that don't, take on a different size, and often a different position. Often they are located in about the center of the screen. My guess is if you change the default figure position to the second monitor some of the the dialog boxes would follow, but not all.
Walter Roberson
el 25 de Sept. de 2011
Unfortunately I cannot test dual monitors.
There is a private function used by the dialog boxes, something about "getnicedialogposition"; my access to my server is down again today so I cannot read the source at this time.
Ver también
Categorías
Más información sobre Environment and Settings en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!