How to display figure on a specific monitor when there are multiple screens
96 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
MathWorks Support Team
le 10 Juin 2020
Commenté : DGM
le 2 Oct 2024
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.
Réponse acceptée
MathWorks Support Team
le 18 Jan 2024
Modifié(e) : MathWorks Support Team
le 29 Fév 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:
1 commentaire
DGM
le 2 Oct 2024
There's this cool new thing called hypertext. It lets us access web pages directly in our browser instead of needing to run commands in MATLAB.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Startup and Shutdown dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!