Screen Resolution Limit to Figure Size

83 views (last 30 days)
I'd like to make a bit of code to create images targeted at a 4k display. Unfortunately, I don't own a 4k display. I do, however, have 3 1080 screens. Ordinarily I set them up in a row so my screen appears to MATLAB to be 1080 x 5760.
In this configuration if I run the below code with screen_fraction set to 1 or greater the images created are 1014 high (the maximum sized image always seems to have 66 fewer pixels than the apparent screen size).
If I tell Windows the displays are actually in a diagonal before starting MATLAB I can create a figure 2862 x 5088 before getting a java error.
Obviously then, MATLAB is limiting the figure size to the physical screen sizes but is capable of working with much bigger "displays."
The MonitorPositions and ScreenSize properties of get(groot) are read-only so I can't change them. Is there any other way to work around the connection to the physical size of the monitors?
Yes, I could use imwrite or print to work around this but I'd like to avoid that if possible.
Thanks in advance.
clearvars
screen_fraction = .5;
monitor_size = [1920 1080];
figure_pixels = fix(screen_fraction * monitor_size);
figure_offset = [1.25 0.25] .* monitor_size;
set(gcf,'units','pixels','Position',[figure_offset figure_pixels]);
% something to plot here
[XX,YY,ZZ] = peaks(25);
h = surf(XX,YY,ZZ);
F2I = frame2im(getframe(gcf));
target_size = fliplr(figure_pixels)
actual_size = size(F2I(:,:,1))

Accepted Answer

Rajesh Balagam
Rajesh Balagam on 11 May 2018
At present it is not possible to create a MATLAB figure window that is larger than the connected screen size. This is a constraint enforced by the OS/Window Manager.
If you want the app to resize based on the actual screen size (e.g. when connected to a 4k display), you can try the following workarounds:
  • Design the app within the smaller screen size, in the OpeningFcn read the screen size and make the figure proportionately larger, then use normalized units or write a sizechangedfcn to resize the content.
  • Use the Figure's WindowState property to maximize the figure in the OpeningFcn
  2 Comments
Wick
Wick on 11 May 2018
Thanks. I kind of expected as much. It would be nice to have "virtual" monitors that MATLAB thinks exist that aren't necessarily connected, but for my purposes, telling Windows my three monitors are in a diagonal is sufficient.
Fabiano Baroni
Fabiano Baroni on 24 Jun 2021
You can try using xvfb-run for a virtual framebuffer. For example, for creating a very wide virtual screen:
xvfb-run --server-args="-screen 0 20480x1152x24" matlab -softwareopengl < script.m

Sign in to comment.

More Answers (0)

Categories

Find more on Interactive Control and Callbacks in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!