No License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from

3.5 | 2 ratings Rate this file 4 Downloads (last 30 days) File Size: 4.5 KB File ID: #16330 Version: 1.0



Yair Altman (view profile)


11 Sep 2007 (Updated )

displays or hides the Matlab desktop window

| Watch this File

File Information

currentState = setDesktopVisibility(newState)
setDesktopVisibility(newState) sets the Matlab desktop window visibility state. Valid values for newState are true, false, 'on' & 'off' (case insensitive).

Note: when the desktop visibility is false/'off' (i.e. hidden), the command window is not accessible for user input. Therefore, this function is very useful for GUI-based applications but not for regular interactive (command-window) use.

state = setDesktopVisibility returns the current visibility state of the desktop window (prior to any modification). The returned state is either true/false (Matlab 7) or 'on'/'off' (Matlab 6).

A minor modification of this function will enable any interested user to enable/disable (rather than show/hide) the desktop.

curState = setDesktopVisibility;
oldState = setDesktopVisibility('off'); % hide desktop window
oldState = setDesktopVisibility(result>0);
oldState = setDesktopVisibility(true); % restore visibility
Bugs and suggestions:
Please send to Yair Altman (altmany at gmail dot com)
This code relies on undocumented and unsupported Matlab functionality. It works on Matlab 6+, but use at your own risk!


Findjobj Find Java Handles Of Matlab Graphic Objects inspired this file.

MATLAB release MATLAB 6.0 (R12)
Other requirements Java
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (4)
20 Sep 2007 Yair Altman

I think you're being overly harsh, ET: Your 2 lines are indeed the essence of my code, but they don't work on Matlab 6, nor return the current desktop state, nor allow 'on'/'off' inputs, nor handle errors like my code. Also, I have not seen any FEX submission nor newsgroup post on this issue so I believe there's both innovation and usefulness in this submission. Finally, considering the fact that the entire function is only 133 lines, half of them comments/explanations, saying there's "too much code" is a bit exaggerated, IMHO.

Comment only
20 Sep 2007 E T

h = com.mathworks.mlservices.MatlabDesktopServices.getDesktop.getMainFrame

Comment only
20 Sep 2007 E T

to much code...
can be implemented in 2 lines...

h = com.mathworks.mlservices.MatlabDesktopServices.getDesktop.getMainFrame.setVisible(0);pause(1);com.mathworks.mlservices.MatlabDesktopServices.getDesktop.getMainFrame

current status
>> h.isVisible

set new status
>> h.setVisible(0);pause(3);h.setVisible(1)
>> h.setEnable(0);pause(3);h.setEnable(1)

12 Sep 2007 Marek Pijanowski

Great work.

Contact us