Broken GUI: Why does the button callback code work if I copy/paste in debugger but errors in regular runtime?

2 次查看(过去 30 天)
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 in
matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)Sensor_Analysis_2('pushbutton_plotVcurves_Callback',hObject,eventdata,guidata(hObject))
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.

采纳的回答

Alexei M
Alexei M 2017-2-10
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...

更多回答(1 个)

Walter Roberson
Walter Roberson 2017-2-10
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.
  2 个评论
Alexei M
Alexei M 2017-2-10
Hm, it doesn't seem to be working... I think I did go through GUIDE when I created the second version. Also, why is it that one of the push buttons works, but the other buttons do not? Shouldn't ALL the push buttons fail to work if it was an issue with improperly saving it?
Thank you
Alexei M
Alexei M 2017-2-10
Further info: even the first button which was working fails immediately with the same error if I click it again a second time.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Migrate GUIDE Apps 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by