findobj fails in timer call back

3 次查看(过去 30 天)
I was testing a timer in a large program written in GUIDE and I came across these strange results.
function checkfordone_openningFcn(hObject, eventdata, handles, varargin)
handles.t = timer(TimerFcn,@IsDataReady,ExecutionMode,fixedRate,Period,4);
start(handles.t)
function IsDataReady(timerObject, eventdata)
fHandles = findobj(type,figure,tag,figure1)
end
The findobj command in the timer function callback, IsDataReady, returns a valid handle to figure1 the first time it is called. After that it only returns null.

采纳的回答

Paul
Paul 2012-3-30
I provide the solution to this problem because it took days to find; mostly because it was buried deep in the guts of our medium size deployable application.
In GUIDE, the main figure, figure1, had it’s HandleVisibility set to callback which is the default. This means that “handles are visible from within callback routines or function invoked by callback routines, but not from within functions invoked from the command line.” HandleVisibility can also set to ‘on’ or ‘off’. In the above code, the first time IsDataReady was called it was as a callback and thus findobj found the handle. Every time after that the timer must be executing in a different space and findobj returns null. The solution is to change HandleVisibility of the parent figure to ‘on’ or to use the findall command.
fHandles = findall(0,type,figure,tag,figure1)
Here the zero signifies the root object and thus all the children are searched.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Graphics Object Programming 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by