corruption of handles and hObject / GUIDE application

1 次查看(过去 30 天)
I have this odd problem within a call back function for a GUI created with 'guide' (this is my first gui app). The handles and hObject variables seem to get corrupted when I call a function (my own function).
case A: This works as expected
function updateButton_Callback(hObject, eventdata, handles)
% hObject handle to updateButton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
set(handles.statusUpdater1,'String','start');
%[retcode,retmsg]=MyFunction('dog', 'cat');
set(handles.statusUpdater1,'String','finish');
Case B: This Doesn't work Same as above with the MyFunction() line uncommented. The console error for the 2nd set is: "??? Error using ==> set Invalid handle object." Also hObject appears to be gone too. I tried copying the two before calling the function and restoring, but that didn't help.
Is there anyway that a function call could kill these locals? Is there a way to re-extract these two directly from the "gui_state" or somewhere else in a"guide" built application/m-file?

采纳的回答

Al
Al 2011-6-28
Ha! Sorry. It turned out that the MyFunction(), a complicated tree of functions, had a "close all" buried in it (to close all plots). I guess the 'close all' closes, at least partially, the caller's GUI; but the odd thing is that the application GUI doesn't "close" it just doesn't work anymore.

更多回答(1 个)

Paulo Silva
Paulo Silva 2011-6-28
Try this way:
function updateButton_Callback(hObject, eventdata, handles)
% hObject handle to updateButton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
sU1H=handles.statusUpdater1;
set(sU1H,'String','start');
[retcode,retmsg]=MyFunction('dog', 'cat');
set(sU1H,'String','finish');

类别

Help CenterFile Exchange 中查找有关 Entering Commands 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by