ERROR USING SET() ? GUI, Handles

1 次查看(过去 30 天)
Paulo
Paulo 2011-8-27
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 个评论
Jan
Jan 2011-8-27
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.

请先登录,再进行评论。

回答(1 个)

Paulo Silva
Paulo Silva 2011-8-27
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 个评论
Paulo
Paulo 2011-8-28
Would I just include the "best solution functions" on my code after the while loop? or inside the while loop?

请先登录,再进行评论。

类别

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