Ahh I figured it out! Sorry to pollute cyberspace with possibly not very useful info, but the problem was that I was changing directory. I was trying to make it so that every time I click Load files after the first time (the program is intended to do so multiple times), that the open file dialog box starts essentially in the directory where I left off. But I didn't realize changing Matlab's directory while a program is running kills it. Should've known. I'll need to figure out a different way to accomplish what I want...
Broken GUI: Why does the button callback code work if I copy/paste in debugger but errors in regular runtime?
1 view (last 30 days)
Show older comments
I've been building/coding a GUI (using GUIDE). At some point I "forked it". That is, my Sensor_Analysis.fig & .m files are now Sensor_Analysis2.fig & .m. Some time later this thing became broken, and it makes absolutely no sense why I'm getting a (totally uninformative) error.
The way my GUI works is I have a "load files" button, and it does some calculations after files are loaded. Then I have buttons for plotting and saving. The load files callback runs with no errors, but when I subsequently click the other buttons, I get this error:
Undefined function or variable 'Sensor_Analysis_2'.
Error while evaluating UIControl Callback
If I put in a breakpoint in the editor right at the end of my load files button callback, run the code up to that point, and then simply copy the next button's code into the Matlab command window, and execute it, then it works! But as soon as I try to use the button in the GUI again, I get the error.
What's going on here?? Really mystified and frustrated.
More Answers (1)
Walter Roberson on 10 Feb 2017
GUIDE stores the names of the routine to call as properties of the graphics object in the .fig . If you rename your GUI's .m without going through GUIDE, then the properties of the graphics object do not get updated, and so it cannot find the routines it needs.
It is possible to repair in place, but the easier approach is to temporarily rename your GUI's .m back to Sensor_Analysis_2 (note that is not Sensor_Analysis2) and then go into GUIDE and tell GUIDE you want to save it as some other name; it will update the graphics object properties.
Find more on Migrate GUIDE Apps 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!