ERROR USING SET() ? GUI, Handles

1 Ansicht (letzte 30 Tage)
Paulo
Paulo am 27 Aug. 2011
my code is like this: while microcontroller is connected
if(face detected) set(handles.statusLbl,'String','Capturing iris image . . .'); else set(handles.statusLbl,'String','Idle');
end while
statusLbl is a static text in the GUI
And When I exit the program, an error occurs...
Error using
==> set
Invalid handle
object.
Error in ==> irisrecognition>irisrecognition_OpeningFcn at 124 set(handles.statusLbl,'String','Idle');
Error in ==> gui_mainfcn at 221 feval(gui_State.gui_OpeningFcn, gui_hFigure, [], guidata(gui_hFigure), varargin{:});
Error in ==> irisrecognition at 42 gui_mainfcn(gui_State, varargin{:});
  1 Kommentar
Jan
Jan am 27 Aug. 2011
What is your question?
You can use the debugger ("dbstop if error") to find out, why the opening function is called when you stop the program. But there is no chance, that we can guess the cause of the problem.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Paulo Silva
Paulo Silva am 27 Aug. 2011
It looks like you have your code inside a while loop, when you exit your GUI the handles are deleted but the loop still tries to set the string of the static text (at least once), the fast solution would be:
try
if(face detected)
set(handles.statusLbl,'String','Capturing iris image . . .');
else
set(handles.statusLbl,'String','Idle')
end
catch
end
The best solution would involve checking if the handles.statusLbl is still a valid handle before setting the text string.
Some functions that might be helpful
any(ismember(who,'handles')) %check if theres one handles variable
strcmp(class(handles),'struct') %check if handles is a structure
isfield(handles,'statusLbl') %check if handles got one field called statusLbl
ishandle(handles.statusLbl) %check if the statusLbl is a valid handle
  2 Kommentare
Paulo
Paulo am 28 Aug. 2011
Would I just include the "best solution functions" on my code after the while loop? or inside the while loop?
Paulo Silva
Paulo Silva am 28 Aug. 2011
inside it

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by