- Undocumented Matlab - https://undocumentedmatlab.com -
Setting the Matlab desktop layout programmatically
Posted By Yair Altman On June 24, 2009 | 6 Comments
The Matlab desktop enable users to switch between different presentation layouts of the desktop panels (Command Window, Workspace etc.). This has been supported as far back as Matlab 6 (R12), with newer Matlab releases adding improved functionality such as the ability to save user-defined layouts, as Kristin explained in the official Matlab desktop blog [1].
The only supported way to save and switch layouts is to use the desktop’s main menu. Since Kristin has posted her write-up, a few people have posted unanswered follow-up comments requesting to know how to programmatically save and switch layouts. I will now show how this can be done.
First, we need to get the Java handle of the Matlab desktop. We can then investigate this handle using the built-in methodsview function or my UIInspect utility [2] on the File Exchange. We quickly see the relevant layout-related functions, which we can put to good use:
% Get the desktop's Java handle (Matlab 7 only) desktop = com.mathworks.mde.desk.MLDesktop.getInstance; % Inspect the available desktop functions methodsview(desktop); uiinspect(desktop); % Save the current layout desktop.saveLayout('Yair'); % Switch between different layouts desktop.restoreLayout('Yair'); desktop.restoreLayout('Default'); desktop.restoreLayout('History and Command Window');
% Get the desktop's Java handle (Matlab 6 only) desktop = com.mathworks.ide.desktop.MLDesktop.getMLDesktop; % Inspect the available desktop functions % Note: in Matlab 6, methodsview() did not accept object handles methodsview('com.mathworks.ide.desktop.MLDesktop'); %uiinspect(desktop); % UIINSPECT does not work on Matlab 6 % Save the current layout % saving the desktop is not possible in Matlab 6 % Switch between different layouts desktop.set5PanelLayout; desktop.setTallLayout; desktop.setShortLayout; desktop.setDefaultDesktop; desktop.setMolerMode; % ='Command window only'
Categories: Desktop, High risk of breaking in future versions, Java
Article printed from Undocumented Matlab: https://undocumentedmatlab.com
URL to article: https://undocumentedmatlab.com/articles/setting-the-matlab-desktop-layout-programmatically
URLs in this post:
[1] as Kristin explained in the official Matlab desktop blog: http://blogs.mathworks.com/desktop/2007/08/29/i-came-i-saw-i-created-my-own-desktop-layout/
[2] UIInspect utility: http://www.mathworks.com/matlabcentral/fileexchange/17935
[3] setPrompt – Setting the Matlab Desktop prompt : https://undocumentedmatlab.com/articles/setprompt-setting-matlab-desktop-prompt
[4] Setting desktop tab completions : https://undocumentedmatlab.com/articles/setting-desktop-tab-completions
[5] Changing system preferences programmatically : https://undocumentedmatlab.com/articles/changing-system-preferences-programmatically
[6] Setting status-bar text : https://undocumentedmatlab.com/articles/setting-status-bar-text
[7] Matlab layout managers: uicontainer and relatives : https://undocumentedmatlab.com/articles/matlab-layout-managers-uicontainer-and-relatives
[8] Listbox layout customization : https://undocumentedmatlab.com/articles/listbox-layout-customization
[9] : http://www.mathworks.com/matlabcentral/fileexchange/44040-lyt-matlab-desktop-layout-load-or-save
Click here to print.
Copyright © Yair Altman - Undocumented Matlab. All rights reserved.
6 Comments To "Setting the Matlab desktop layout programmatically"
#1 Comment By Troykapoika On March 16, 2011 @ 01:06
I would like to know if there is any way to organize (remove) layouts programmatically? I have played around with uiinspect looking for the calls to organize and remove layouts, but I haven’t been too successful. Also, do you know if there is anyway to share layouts between computers and load them into MATLAB without having to restart MATLAB?
Thanks!
Troy
#2 Comment By Sky On October 24, 2013 @ 02:23
This post inspired me to make a small utility ( [9]) that I personally use very often and find quite useful. Hopefully others will too. Thank you for the post. I’d love to get feedback on the file if you have any for me.
#3 Comment By Yair Altman On October 24, 2013 @ 02:35
nice 🙂
#4 Comment By Anderson On April 29, 2014 @ 12:40
Hi,
Is there a command similar to desktop.closeCommandWindow, so that I can close/open editor window and figures window?
Thank you
#5 Comment By Yair Altman On April 29, 2014 @ 12:50
@Anderson:
#6 Comment By Dominik On March 24, 2016 @ 11:47
Dear Yair,
thank you for all those helpful matlab secrets!
I was wondering how to arrange figures in my tiled custom desktop group.
The group I create like that:
And the figures I associate via:
Now I would ideally like to control in which pane the figures are created and, possibly be able to create tabbed figures within one pane.
I would be delighted about any hint.
Thank you!