Assign timer function from another file to global object

2 ビュー (過去 30 日間)
Ryan Sinfield
Ryan Sinfield 2016 年 11 月 23 日
コメント済み: Ryan Sinfield 2016 年 11 月 23 日
I have a global audioplayer object that is used by two different GUIs.
GUI1.m
global ap;
% functions and stuff...
function toBeCalled(obj, evt, a)
% Timer function for ap
GUI2.m
global ap;
function assignTimerFcn()
% set the TimerFcn for ap
ap.TimerFcn = {@toBeCalled, 2};
I get an error message stating that the function doesn't exist when I play the audioplayer object if the TimerFcn is set this way.
Is there something else I need to specify in order to tell Matlab that I intend to use the toBeCalled function from GUI1.m instead of looking for a toBeCalled function in GUI2.m?
Thanks

採用された回答

Jan
Jan 2016 年 11 月 23 日
編集済み: Jan 2016 年 11 月 23 日
If the "toBeCalled" function is a subfunction of the GUI1.m file, you cannot access it directly from anywhere else. Move "toBeCalled" in an own M-file to allow this.
This is not a problem of timers or guis, but the wanted behavior of subfunctions.
  2 件のコメント
Ryan Sinfield
Ryan Sinfield 2016 年 11 月 23 日
Thanks, I'll give that a go
Ryan Sinfield
Ryan Sinfield 2016 年 11 月 23 日
That worked thanks!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeWhos についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by