The same default position and size is independent of the screen resolution on different computers

I am working with MATLAB on the right half of the screen, so I want the numbers to open on the left half of the screen. However, the height of the shape should be approximately equal to the default size, not the height of the screen. Also, I am using MATLAB on different computers with variable screen size (pixels), so the size of the figure should depend on the screen size, but the same numbers are displayed on the screen. Therefore, the size and position of the shape depends on the screen resolution, but the code that creates the size and position must be independent of it.

I accomplished this with the code in my answer below, which I thought I would share for those who find it useful for their own setup.

+3


source to share


1 answer


The current MATLAB folder by default can be set in MATLAB preferences. I have installed this to a network folder on all my MATLAB computers, it can also be a cloud service cloud folder for example. Dropbox. Then I put the file startup.m

in that folder containing the following code.

ss = get(0,'screensize');
b = 7; % border around figures is 7 pixels wide
%TODO different for various operating systems and possibly configurations.
p = 0; % extra padding pixels from left edge of screen

if ispc
    win = feature('getos');
    i = (1:2) + regexp(win,'Windows ','end');
    switch win(i)
        case '10'
            b = 0;
            p = 2;
        otherwise
            % other cases will be added in the future
    end
end

fwp = ss(3)/2-2*b-p; % figure width in pixels
b = b+p;
n = 5;
set(0,'defaultfigureposition',[b ss(4)/n, fwp, ss(4)*(1-2/n)])
clear

      

Now, every time I start MATLAB, it runs this script and it moves the defaults I create to the left half of the screen with a good size (the axes are just a little wider than they are tall).

Curly units are normalized, but you can adjust them to pixels or any other measure you like. I hope someone finds this script useful for setting them up.



EDIT: I updated the script to keep the default units: pixels. This is necessary because applications like Curve Fitting Tool ( cftool

) or Classification Learner ( classificationLearner

) and possibly others listen with normalized shape units. Their (dialog) windows are either not displayed (they are located outside the screen area), or too small or too large.

EDIT 2: I updated the script to be compatible with Windows 10. Now the number windows have a border of 1 pixel, not 7. Also, the numbers are padded a little on the right because Windows 10 puts them too far to the left. Windows 10 is automatically detected.

DO: Support for additional operating systems (with detection), eg. Mac, Linux. If you have such a system, please let us know in the comment:

  • Open MATLAB and copy the resulting line from the command feature getos

    here.
  • Position the shape opposite (not on or above) the left edge of the screen and opposite (not on or above) the right half of the screen and report the position and outer position of the piece here.
+2


source







All Articles