GUI stops after initialization code

6 views (last 30 days)
Laura F
Laura F on 4 Oct 2019
Edited: Adam Danz on 26 Dec 2019
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?
  11 Comments
Rik
Rik on 4 Oct 2019
Well Adam, your encouragment (and the fact that there now is a huge banner that GUIDE will be removed) pushed me over the egde, so I now posted a thread about this. Please feel free to weigh in.

Sign in to comment.

Accepted Answer

Adam Danz
Adam Danz on 4 Oct 2019
Edited: Adam Danz on 26 Dec 2019
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
  2 Comments
Laura F
Laura F on 4 Oct 2019
Thank you very much. This worked.
Adam Danz
Adam Danz on 21 Nov 2019
In case you're working with your GUI in r2019b, I wrote a patch to try to solve the problem of accessing the GUI while avoiding the bug in the r2019b release. If you find yourself dealing with that problem, here's a solution.

Sign in to comment.

More Answers (1)

Rik
Rik on 4 Oct 2019
Did you notice this line?
% Begin initialization code - DO NOT EDIT
They weren't kidding. It is easy to mess up GUIDE-created GUIs. I'm not seeing the closing of this comment, so something happened to that code. Somehow the code responsible to making the GUI visible isn't running. The code below should be a temporary fix to make your GUI visible again.
h=GUI_start;
set(h,'Visible','on')
  2 Comments
Laura F
Laura F on 4 Oct 2019
Yes I noticed this line. And
% End initialization code - DO NOT EDIT
is the only thing that is missing there. I cecked it by creating a new GUI. I really didn't change anything there.
Okay Thank you. This is working :-)
Adam Danz
Adam Danz on 4 Oct 2019
Visibility was indeed the issue but the user would have to run this line of code every time they access the GUI. Even if this line below were placed in the opening function, the GUI will still not stay visible as long as the visibility parameter in the figure file is set to 'off' which can only be changed through GUIDE.
handles.figure1.Visible = 'on';

Sign in to comment.

Categories

Find more on Interactive Control and Callbacks in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!