How to display figure on a specific monitor when there are multiple screens

96 visualizzazioni (ultimi 30 giorni)
I use a computer with multiple screens. I would like to have my new figures spawn on a screen that I specify instead of the main display screen. It would be wonderful if MATLAB could detect the number of displays connected, and let me pass the display number to "figure". If the display vanishes during the execution, fall back to alternate displays.
It would be nice to have a method where I did not have to compute the pixels. If the code executes after a monitor gets disconnected the figure is out of the viewable screen.

Risposta accettata

MathWorks Support Team
MathWorks Support Team il 18 Gen 2024
Modificato: MathWorks Support Team il 29 Feb 2024
There is no way to use "figure" to explicitly set which monitor the figure displays on, but there is a workaround that is fairly straightforward.
Using the "MonitorPositions" root object you can get the position of each display in MATLAB "Position" arguments.
 
Please run the below command in the MATLAB R2018b command window to access the release specific documentation. For more information on "MonitorPositions," refer to the "Display Information" section within the documentation:
web(fullfile(docroot, 'matlab/ref/matlab.ui.root-properties.html'))
And then you can set the "Position" of the figure to that. To do this for the secondary monitor execute the following MATLAB commands:
>> p = get(0, "MonitorPositions")
>> f.Position = p(2, :) % second display
>> f.WindowState = "maximized"
Using "WindowState" set to "maximized" prevents overlap with docks and status bars on the screen.
To do this for the primary monitor, this code applies:
>> f.Position = p(1, :) % first display
>> f.WindowState = "maximized"
If you want every figure to open in the size the current figure is, you can set the "DefaultFigurePosition" in the graphics root settings. For more information, you can run the following command in MATALAB R2018b command prompt to view the "Default Property Values" documentation page:
 
web(fullfile(docroot, 'matlab/creating_plots/default-property-values.html'))
>> set(0, "DefaultFigurePosition", f.Position
To undo this and return figures to their standard default settings, execute
>> set(0, "DefaultFigurePosition", 'remove')
Please follow the below link to search for the required information regarding the current release:

Più risposte (0)

Categorie

Scopri di più su Startup and Shutdown in Help Center e File Exchange

Prodotti


Release

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by