MATLAB Answers

In MATLAB, how do I obtain information about my screen resolution and screen size?

496 views (last 30 days)
Using MATLAB, I want to obtain information about my screen resolution and screen size.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 27 Jun 2009
MATLAB uses certain APIs in order to get information about the size and resolution that the system is using. The information returned is made available to the user through the Root properties 'ScreenSize' and 'Units'. The following example demonstrates how to use these properties:
%Sets the units of your root object (screen) to pixels
set(0,'units','pixels')
%Obtains this pixel information
Pix_SS = get(0,'screensize')
%Sets the units of your root object (screen) to inches
set(0,'units','inches')
%Obtains this inch information
Inch_SS = get(0,'screensize')
%Calculates the resolution (pixels per inch)
Res = Pix_SS./Inch_SS
On the test machine used for this example, this was the result:
Res =
Inf Inf 96.0000 96.0000
This means that my screen has a resolution of 96 pixels per inch in both the x and y directions.
You can confirm these numbers on a Windows 2000 machine by right-clicking on the desktop and selecting Properties -> Settings -> Screen Area. This will display the number of pixels per inch which should match the number obtained by the command:
Pix_SS = get(0,'screensize')
NOTE: Sometimes inaccuracies creep into the results you may get. This is due to the fact that the system may return incorrect information. If you begin to notice this, you can compensate by updating the video drivers or switching the resolution of the monitor. However, this is rare.

  2 Comments

James Ang
James Ang on 29 Apr 2016
Hi,
I tried the code above and changed my screen resolution (right clicking on desktop>>screen resolution>>changing the resolution.)
The output that I received are all the same no matter what resolution I selected(i.e I always received 1680-1050 for the output)
%Sets the units of your root object (screen) to pixels
set(0,'units','pixels')
%Obtains this pixel information
Pix_SS = get(0,'screensize')
%Sets the units of your root object (screen) to inches
set(0,'units','inches')
%Obtains this inch information
Inch_SS = get(0,'screensize')
%Calculates the resolution (pixels per inch)
Res = Pix_SS./Inch_SS
Pix_SS =
1 1 1680 1050
Inch_SS =
0 0 17.5000 10.9375
Res =
Inf Inf 96 96
Is there a way to obtain the screen resolution as I'd changed?
Walter Roberson
Walter Roberson on 29 Apr 2016
You will need to use Java methods for that. The root properties are not refreshed dynamically.

Sign in to comment.

More Answers (2)

Alec Jacobson
Alec Jacobson on 22 Oct 2016
On my macbook air, if I issue
On my macbook air, if I issue
set(0,'units','pixels')
get(0,'ScreenSize')
I get
1 1 1440 900
and
set(0,'units','inches')
get(0,'ScreenSize')
I get
0 0 20 12.5
using this I would compute that I have a 72 pixels per inch resolution screen. However, this screen is actually 128 ppi (obviously the macbook air is not 20inches wide).
How can I get the true physical size (and true resolution) of my screen?

  1 Comment

Walter Roberson
Walter Roberson on 22 Oct 2016
If you are sufficiently new MATLAB, then as part of trying to make high resolution work smoothly, they locked the apparent resolution.
  • On Windows® systems, the value is 96 DPI.
  • On Macintosh systems, the value is 72 DPI.
  • On Linux® system, the value is determined by your system resolution.
Note: Starting in R2015b on Windows systems, if the Units property is set to 'pixels', then the width and height values might differ from the screen size reported by the operating system. The values MATLAB reports are based on a pixel size of 1/96th of an inch. On Macintosh and Linux systems, the values match the size reported by the operating system.

Sign in to comment.


Dominik Mattioli
Dominik Mattioli on 18 Dec 2018
Res = get(0,'ScreenPixelsPerInch')
This functionality might have been added since MathWorks originally posted their own answer above.

  0 Comments

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!