MATLAB: In MATLAB, how to obtain information about the screen resolution and screen size

displayinchMATLABpixelresolutionscreensize;

Using MATLAB, I want to obtain information about my screen resolution and screen size.

Best Answer

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.