findobj fails in timer call back

2 ビュー (過去 30 日間)
Paul
Paul 2012 年 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 Center および File ExchangeMigrate GUIDE Apps についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by