TimerFcn within GUI function to another GUI function
3 ビュー (過去 30 日間)
古いコメントを表示
I am attempting to call one gui function from a gui function in a gui script so that I can pass various handles around.
Essentially how the program works is: Checkbox to stream data.
function Checkbox_Callback(hObjects,eventdata,handles)
onoff = get(hObject,'Value');
if onoff == 1
a = timer;
set(a,'executionMode','fixedRate','Period',1,'TimerFcn','Stream');
start(a)
elseif onoff == 0
stop(a)
end
The next function is used to call the data from an external program. The function definitely works, it's just the issue of how to call it correctly from the set(a,'TimerFcn',XXXXXXXXX);
The "Stream" function is along these lines:
function Stream(hObject,eventdata,handles)
XPNetConnect();
out = XPNetRecv();
variable1 = out.Variable1;
... etc
%Calculations
handles.Value = something;
guidata(hObject, handles);
Run_Another_Callback(hObject, eventdata, handles)
Hopefully you get the gist of what I'm trying to do.
I would really appreciate the help.
Thank you in advance.
0 件のコメント
採用された回答
Daniel Shub
2012 年 3 月 1 日
I would do things a little differently ...
Make your timer object when you make your gui. If you do it at this point, all the handles that Stream needs are known.
You could do:
handles.htimer = timer('executionMode', 'fixedRate', 'Period', 1, 'TimerFcn', @(h, evt)Stream(h, evt, handles));
Note the specification of TimerFcn as
@(h, evt)Stream(h, evt, handles)
You would then rewrite Checkbox_Callback to be
function Checkbox_Callback(hObject,eventdata,handles)
if get(hObject,'Value')
start(handles.htimer)
else
stop(handles.htimer)
end
その他の回答 (2 件)
Sean de Wolski
2012 年 3 月 1 日
use setappdata/getappdata for the required handles and timerfind to find the appropriate timers.
John
2012 年 3 月 2 日
3 件のコメント
Nope
2012 年 5 月 17 日
What do you mean by that? I'm having the exact same problem and can't find a solution. What do you mean pass the additional variables, by the looks of the code you're passing all 3 variables already? Please help.
Cait
2012 年 7 月 13 日
Yes, I am also experiencing the same problem. I get the "H must be the handle to a figure or figure descendent."
And then "Reference to non-existent field 'gotimer'", which is what I'm calling my timer the next time I call it.
What did you do?
参考
カテゴリ
Help Center および File Exchange で Migrate GUIDE Apps についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!