MATLAB: How to adjust the shape on the second monitor screen?

I only use an external monitor connected to my laptop (laptop screen is off). When I try to make a MATLAB shape fit the screen, it only gets a size large enough to fit the laptop screen (which has a lower resolution). I am using the following:

figure('outerposition',get(0,'screensize')); % or 'monitorpositions'

      

I even tried:

figure('outerposition',[0 0 1 1.2]);

      

but it does not, and the pattern is only suitable for part of the monitor screen.

Any help would be greatly appreciated as I am out of idea.

P.-S. In the end, I would like the shape to fit 90% of (for example) the screen (width and height).

Thanks in advance!

+3


source to share


2 answers


The problem may be related to this note in the documentation :

MATLAB sets the display information values ​​for this property at startup. The values ​​are static. If the system settings are displayed, the values ​​are not updated. To update the values, restart MATLAB.

On my desktop, starting with Matlab with only one active screen, you can:

>> get(0,'MonitorPositions')
ans =
           1           1        1280        1024

      

and even if I try to activate the screen later, it doesn't change . However, if I activate the second screen and then restart Matlab, I get:



>> get(0,'MonitorPositions')
ans =
       -1919        -123        1920        1080
           1           1        1280        1024

      

And then I can set a digit like this:

figure('OuterPosition',[-1920 -123 3200 1080]);

      

which covers both screens.

+1


source


This solution is based on a function screensize

written by Doug Schwartz on this Newsreader thread .

I did some quick tests, they seem to return the desired results, find my adaptation at the bottom of this post.

Usage example

Full screen, monitor 2

% Pass the monitor number to the screensize function, this example uses monitor 2
sz = screensize(2); 
% The function returns pixel values, so must use units pixels
% Set the outerposition according to that.
figure('units', 'pixels', 'outerposition', sz)

      



Just filling 90% of the screen, monitor 2:

sz = screensize(2);
pad = 0.05; % 5% padding all around
szpadded = [sz(1:2) + sz(3:4)*pad, sz(3:4)*(1-2*pad)];
figure('units', 'pixels', 'outerposition', szpadded); 

      

screensize

function

Doug's original code relied on moving the mouse pointer to get positions, I'm not sure why and minified this code. I also removed code duplication, etc. to make things a little more compact. The function mainly relies on getting an array of screen devices from the back of java.

function ss_out = screensize(screen_number)
%screensize: return screen coordinates of multiple monitors.
    % Version: 1.0, 26 June 2008 Author: Douglas M. Schwarz
    % Version: 1.1, 21 July 2017 Author: Wolfie 
    persistent myss
    if isempty(myss)
        % Get Screen Devices array.
        sd = java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment.getScreenDevices;
        % Initialize screensize array.
        num_screens = length(sd);
        myss = zeros(num_screens,4);
        % Loop over all Screen Devices.
        for ii = 1:num_screens
            bounds = sd(ii).getDefaultConfiguration.getBounds;
            myss(ii,:) = [bounds.x, bounds.y, bounds.width, bounds.height];
        end
    end
    num_screens = size(myss,1);
    if nargin == 0
        screen_number = 1:num_screens;
    end
    screen_index = min(screen_number,num_screens);
    ss_out = myss(screen_index,:);
end

      

+1


source







All Articles