Consistent GUI screen sizing on laptop and monitor

Hi, so I have a GUI that I mainly work on at the internship I have, where I use a 1920x1080 resolution monitor. I verified that Matlab was using this same resolution by doing the get(0,'screensize') command. However, I went to work on it at home on my laptop, which is also 1920x1080 resolution, and the layout for the GUI is all messed up. Furthemore, when I did get(0,'screensize'), it says the resolution is 1280x720 even though I'm positive my laptop's screen is 1920x1080 resolution. How do I fix this so that my GUI works on both my laptop and the monitor I work on? Is there some command I can do on my laptop where I can change the Matlab resolution to 1920x1080? Does it have something to do with the fact that my laptops screen is physically smaller than the monitor screen (13'' vs roughly 24'')?

8 Kommentare

Hi,
Can I know which MATLAB version you are using ? And also you built your GUI using GUIDE or appdesigner ?
I'm using MATLAB version R2019A on the monitor setup, but then R2018B on my laptop. I built my GUI programmatically, without using GUIDE or appdesigner.
Rik
Rik am 14 Aug. 2019
Do you have display scaling enabled in Windows? It sounds like a high enough resolution for such a small screen that you have. I have never before had any issues in that regard, but that might be a cause.
Rik
Rik am 19 Aug. 2019
Comment posted as answer by JIAYING WU:
Same issue with the app designer.
Did anybody know why Matlab get() gets 1280x720, differ from the actual 1920x1080?
Rik
Rik am 19 Aug. 2019
I suspect this may have something to do with display scaling for high pixel density screens, but I haven't confirmed it. There is a 1.5x factor between those two, which is a common setting for display scaling.
Please confirm that you are not connecting your laptop to an external monitor - in this case monitor 0 might refer to the external monitor and not your laptop (depending on your selected displays layout).
get(0,'MonitorPositions')
will show you the layout and size of all active monitors that Matlab recognizes.
@Rik Display scaling was exactly the issue, mine was set to 150% and when I changed it back to 100%, it worked. Thanks for the helpful response! One more thing though, so when I disable display scaling unfortunately it causes my screen to look pretty zoomed out- having the display scaling is ideal. With this in mind, is there any easy way to scale my gui to work when the display is scaled?
Rik
Rik am 20 Aug. 2019
I don't know how you could solve this, but I suggest you contact Mathworks support to see if they consider this a bug.

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Chidvi Modala
Chidvi Modala am 14 Aug. 2019

0 Stimmen

You can set all the 'units' properties of all the controls to 'normalized'. You can also set the Position property to [0 0 1 1], if you want full screen.

6 Kommentare

Ok thank you. One more question, so I already have a bunch of the objects in my GUI sized in units of pixels, is there some conversion I need to do on those pixel dimensions before changing the 'units' property to 'normalized'? If so, how would I go about doing that?
Rik
Rik am 14 Aug. 2019
Comment posted as answer by Chidvi Modala:
No, It is not required to do any conversion.
Rik
Rik am 14 Aug. 2019
Note that figure('Units','Normalized','Position',[0 0 1 1]) is not the same size as a maximized window. It also doesn't play nice with your Windows taskbar if you have it on your left or right side (instead of the bottom).
When you create an object it has a certain size. If you change the unit, that will not affect the actual position itself, but it will automatically convert the position property. So you will have to figure out the position vectors of your objects in normalized units, which might be as simple as dividing all your pixel based positions by [1920 1080 1920 1080].
Adam Danz
Adam Danz am 14 Aug. 2019
Bearbeitet: Adam Danz am 14 Aug. 2019
@Mason Dyess, the best solution is to just specify 'Units', 'Normalize' for each GUI object within your code. However, here's a way to do that programmatically by running these two lines just after your GUI is created. The first line searches for any object in your GUI that has the "units" property. The second line then changes the units for all of those objects.
objHandles = findall(GUI_figure_handle, '-property', 'Units');
set(objHandles, 'Units', 'Normalize')
Rik
Rik am 14 Aug. 2019
@Adam, actually, that misses a point. That presuposes that all sizes are correct, which is apparently not the case. So Mason would need to run this code on a computer where the sizes turn out correct, and then use the result to adapt the code to generate the GUI with normalized units.
(although to be fair, it isn't entirely clear to me why the layout would break, instead of everything just being scaled down and all proportions staying correct)
Thanks guys, switching to normalized units was pretty helpful for auto-resizing. However, the major issue that was causing me problems was display scaling, so thanks to @Rik for suggesting that as the potential cause.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Chidvi Modala
Chidvi Modala am 13 Aug. 2019

0 Stimmen

I am assuming that you are using GUIDE to build your GUI.

1 Kommentar

Hi, I actually didn't use GUIDE at all to build my GUI. I instead programmatically built it using commands like uicontrol.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Environment and Settings finden Sie in Hilfe-Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by