MATLAB: GUI stops after initialization code

guiguideinitialization code

The GUI was running. Then I added another push button in GUIDE. After that I tried to run the GUI again, but it doesnt work anymore. I figured out, that its only executing until the end of the initialization code. Other breakpoints are not even reached. Restarting Matlab doesnt help either. What could be the problem her?

Best Answer

The problem
The "visible" property of your GUI figure was set to "off" which means the GUI was initialized properly, you just couldn't see it. As evidence, run your current version of the GUI that does not display the figure and then run this line of code which searches for figures even if they are invisible.
findall(0,'type','figure')
The solution
If you're working with Matlab r2019a or earlier, follow these steps.
  1. Remove any breaks in your GUI code and close the m-file.
  2. Open the GUI in GUIDE: guide('GUI_start')
  3. right-click the GUI background and select Property Inspector
  4. scroll down to "Visible" and check "on"
  5. Save the GUI in GUIDE and close the GUIDE window
  6. Now when you open your GUI it should be visible.
If you're working with Matlab r2019b, the problem is a bit deeper. Starting in r2019b an annotationPane handle is included in GUIDE GUIs and this handle was not present in GUIDE GUIs prior to r2019b. I brought this to the attention of the forum last week in this post. If you follow the instructions above in r2019b, you'll get an error as soon as you follow step #4 (selecting the Visible checkbox). The error is associated with the AnnotationPane class, shown below. If you're working with r2019b, instead of following the instructions above, you can just download the attachments which are your GUI files after I've completed the 6 steps above in r2019a. Alternatively, you can try the patch described in the first solution here.
[Update 26-Dec-2019]: Update #3 for r2019b fixes this problem: https://www.mathworks.com/support/bugreports/2083859