ERROR USING SET() ? GUI, Handles

2 visualizzazioni (ultimi 30 giorni)
Paulo
Paulo il 27 Ago 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 Commento
Jan
Jan il 27 Ago 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.

Accedi per commentare.

Risposte (1)

Paulo Silva
Paulo Silva il 27 Ago 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 Commenti
Paulo
Paulo il 28 Ago 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 il 28 Ago 2011
inside it

Accedi per commentare.

Categorie

Scopri di più su Migrate GUIDE Apps in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by