Amelio Vazquez-Reina
Amelio Vazquez-Reina

Reputation: 96350

Move all figures to a specific monitor in MATLAB

I was wondering if there is any known way of moving MATLAB figures to a specific monitor.

I have the following snippet that helps me bring all figures to the front (I got it from Mathworks here):

%% Bring all figures to front
all_figure_handles = findall(0, 'type', 'figure');
for iCount = length(all_figure_handles):-1:1
   figure(all_figure_handles(iCount))
end

And I was wondering if I could ask MATLAB to move all figures to another screen in a similar fashion (i.e. using the handles from all_figure_handles).

Alternatively, if MATLAB is not aware of the monitor partitioning, how could I move all figures to, say, the right half of the total screen space? (in my case, the right half should be the monitor on the right).

Upvotes: 10

Views: 5478

Answers (2)

jorge
jorge

Reputation: 386

Note: You must have your primary monitor on the left to use this

v = get(0,'MonitorPositions') otherwise you get bad coordinates.

Example

primary monitor on the right = Monitor 2 + Monitor 1

type on command window

get(0,'MonitorPositions')

ans =

       1           1        1920        1080
   -1919           1           0        1080

bad coordinates on the second row. You don't have to get negative or zero coordinates

Now, primary monitor on the left = Monitor 1 + Monitor 2

get(0,'MonitorPositions')

ans =

1921           1        3840        1080

1           1        1920        1080

To change the primary monitor on windows 8

Right click desktop, screen-resolution, select-monitor,make this monitor the primary monitor.

Upvotes: 0

Max
Max

Reputation: 2131

From the Matlab figure documentation:

Specifying Figure Size and Screen Location

To create a figure window that is one quarter the size of your screen and is positioned in the upper left corner, use the root object's ScreenSize property to determine the size. ScreenSize is a four-element vector: [left, bottom, width, height]:

scrsz = get(0,'ScreenSize'); figure('Position',[1 scrsz(4)/2 scrsz(3)/2 scrsz(4)/2])

To position the full figure window including the menu bar, title bar, tool bars, and outer edges, use the OuterPosition property in the same manner.

Like this:

set (gcf(), 'outerposition', [25 500, 560, 470])

And furthermore, in the documentation for Root Properties:

MonitorPositions

[x y width height;x y width height]

Width and height of primary and secondary monitors, in pixels. Contains the width and height of each monitor connnected to your computer. The x and y values for the primary monitor are 0, 0 and the width and height of the monitor are specified in pixels.

The secondary monitor position is specified as: x = primary monitor width + 1 y = primary monitor height

Querying the value of the figure MonitorPositions on a multiheaded system returns the position for each monitor on a separate line. v = get(0,'MonitorPositions') v = x y width height % Primary monitor x y width height % Secondary monitor

The value of the ScreenSize property is inconsistent when using multiple monitors. If you want specific and consistent values, use the MonitorPositions property.

Upvotes: 8

Related Questions