Doug's MATLAB Video Tutorials

March 21st, 2011

Adding a debug button to a MATLAB GUI.

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.

2 Responses to “Adding a debug button to a MATLAB GUI.”

  1. J.R.! replied on :

    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.

  2. dhull replied on :

    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


MathWorks

Doug Hull is a proud MathWorker who is on a mission to help you with MATLAB.

Doug's picture

These postings are the author's and don't necessarily represent the opinions of The MathWorks.