corruption of handles and hObject / GUIDE application

조회 수: 4 (최근 30일)
Al
Al 2011년 6월 28일
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에서 Interactive Control and Callbacks에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by