## Stuart’s MATLAB VideosWatch and Learn

### This is machine translation

Translated by
Mouseover text to see original. Click the button below to return to the Original version of the page.

# Adding a debug button to a MATLAB GUI.2

Posted by Doug Hull,

GUIDE GUI’s in MATLAB are really just a series of function calls triggered by callbacks associated with different uicontrols. Because these are all sub-functions, it can be difficult to get into the sub-function at the right time to see the variables that are in scope. This technique allows you do debug a GUI without putting in conditional break points in your code.

### Note

J.R.! replied on : 1 of 2
I think it's easier to get the handles of the GUI-figure, by return the handles like this:
handleGUI = myGUIfunction(params);

and then you can call the handles-structure with the command
handles = guidata(handleGUI);

I used to define exclusively the properties of my GUI, so I can find it later. For example, I set the 'Tag' or the 'Name' of the GUI with a special pattern like 'This is the GUI that I want to find', so I can do later:
handleGUI = findobj(0, 'Tag','This is the GUI that I want to find')

and again:
handles = guidata(handleGUI);

And my preferred solution is (when I defined exclusively my GUI-figure) to create a "Shortcut" which finds the GUI-handle and load the current handles-scructure in to the workspace. In this case you should remember that this method will get the actual state of the GUI, so if you change any value in the GUI, you must get the handles structure again.
dhull replied on : 2 of 2
J.R. I like your method too. There might be problems if your handle visibility is set to 'off' or 'callback', but findall will cure that. Doug