In MATLAB, how do I obtain information about my screen resolution and screen size?
382 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
MathWorks Support Team
il 27 Giu 2009
Modificato: broken_arrow
il 10 Ott 2021
Using MATLAB, I want to obtain information about my screen resolution and screen size.
Risposta accettata
MathWorks Support Team
il 27 Giu 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.
1 Commento
Walter Roberson
il 29 Apr 2016
You will need to use Java methods for that. The root properties are not refreshed dynamically.
Più risposte (2)
Dominik Mattioli
il 18 Dic 2018
Res = get(0,'ScreenPixelsPerInch')
This functionality might have been added since MathWorks originally posted their own answer above.
0 Commenti
broken_arrow
il 10 Ott 2021
Modificato: broken_arrow
il 10 Ott 2021
Concerning size measures in plotting, the fixed "virtual" DPI value on Windows or Linux systems returned by
get(0,'ScreenPixelsPerInch')
means that setting e. g.
figure('Units','pixels','Position',[0 0 1920 1080])
equals a figure size of 1920x1080 screen pixels if the "true" monitor DPI is less than or equal to that "virtual" value (meaning that on a 1920x1080 monitor, the figure will cover the entire screen). For monitors with a true DPI greater than the virtual one, the number of screen pixels per "unit pixel" increases accordingly (props to Walter): https://www.mathworks.com/help/matlab/creating_guis/dpi-aware-behavior-in-matlab.html (thus on a 4K monitor of same size, the aforementioned figure would still cover the whole screen).
The true monitor DPI can be easily calculated manually (Pythagorean theorem) or with an online tool (google "calculate monitor dpi")
1 Commento
Walter Roberson
il 10 Ott 2021
96 is used for Windows. For MacOS it is 72.
Vedere anche
Categorie
Scopri di più su Environment and Settings in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!