How to deactivate GUIs during processing

For some unknown reasons (to me at least), Matlab Figure windows lack a fundamental property, the “ENABLE”.

All the interface control objects (Uicontrol, Uimenu,…) have an Enable property that allow you one fundamental thing : Turn off their behavior.

When you design an interface, this is fundamental because you don’t want your user to press a button if he has already pressed it and a calculation is going on. Or you don’t want the user to change the value of a particular field if one calculation that uses this field has already started.

To give a clear example of why this is important, this is how it would look like.

As you can see, the user has pressed the ‘Apply’ button. A calculation is going on, as can be seen by the presence of a waitbar AND the interface is grayed.

 Now to achieve this behavior is not straightforward, as it would seem, because the figure window does not have this Enable property, so you have to go one by one to turn off all objects in the window. This can prove painfull if you have a lot of objects in there, ie a lot of call to :


A complicated solution that relies on pure undocumented Java properties has been proposed already:

Usually, I don’t like to use undocumented features because, in many cases, they are not supported and might not work on a new release of Matlab. I propose here something much much simpler.

Just use the nice findobj function :

% We turn the interface off for processing.

%                         %
%                         %

% We turn back on the interface

Here findobj finds all the objects with the property Enable that is to ‘On’ and turn them to ‘Off’. It does this search among all the childs of HandleToFigWindow. So replace this last variable with the handle to your gui or whatever you want.

At the end of the calculation, it turns back on your objects. Simple but apparently, nobody had thought about this because I spent quite some time googling until I decided to solve this by myself.

This entry was posted in Intermediate, Making interfaces. Bookmark the permalink.

9 Responses to How to deactivate GUIs during processing

  1. Natalia Anga says:

    Interesting..I tried this today with my GUI… and well, there is a slight problem!! This command “resets” the GUI to the default values…
    so when Enable is turned on again… I lost all the user’s selections
    There may be a way around this… will try to find out more and comment if i find something.

    I have found the website very useful, thanks

  2. Natalia Anga says:

    Well it is not reseting all parameters, only some edit fields….

    • Jerome says:

      I don’t see why it would do this. I have been using this code for a while now and I never had such a problem. A bug in your code or a matlab bug?

  3. Monica says:

    Wow. Really useful. Thanks!

  4. Bharath says:

    Really Useful, Thanks a lot

  5. Hannes says:

    Why don’t you use the ‘WindowStyle’ property and set your input figure ‘WindowStyle’ to ‘modal’? inputlg is using this property. So am I for my selfmade input dialog figures.


    • Jerome says:

      Hi Hannes, seems like another to force interaction with the wait bar, indeed.

      I prefer my solution as it is more intuitive to the user. I am always confused with sticky windows that stay on top. It feels like invasive.

  6. Herb says:

    I also have the same problem that it reset the GUIDE to default setting.

    I think the problem is that I use opening function to define the default setting. And when this code calls findobj(HandleToFigWindow,’Enable’,’on’), it uses the opening function again.

    Is there a method not to reset to default setting???

Leave a Reply

Your email address will not be published. Required fields are marked *