In App Designer I'm having trouble assigning a function handle to TimerFcn.

21 ビュー (過去 30 日間)
Steve Boose
Steve Boose 2018 年 11 月 29 日
コメント済み: Greg 2018 年 11 月 30 日
I'm kind of a newby with App Designer and having trouble assigning a function handle to TimerFcn.
I know the Timer is set up properly because the line:
app.myTimer.TimerFcn = @(~,~)disp('do something'); works fine.
But when I use:
app.myTimer.TimerFcn = @Timer_func; I get "Undefined function 'Timer_func' for input arguments of type 'timer' ".
But the function is in fact defined:
methods (Access = private)
function Timer_func(app)
if app.tval == "Green"
app.tval = 'Red';
elseif app.tval == "Red"
app.tval = 'Green';
end
app.TimerLamp.Value = app.tval;
end
end

採用された回答

Greg
Greg 2018 年 11 月 30 日
編集済み: Greg 2018 年 11 月 30 日
You missed the second half of the error message: "Undefined function 'Timer_func' for input arguments of type 'timer'." Apps in AppDesigner are classdefs, meaning the app is a class. When you define a method inside the .MLAPP file, you've defined it for "input arguments of type [your app]," which means variables like timers can't see that function. Move Timer_func out of the .MLAPP into its own .M or .MLX file on your MATLAB path.
Or, since you appear to need app itself inside the timer callback, use
@(~,~) Timer_func(app)
  2 件のコメント
Steve Boose
Steve Boose 2018 年 11 月 30 日
Thank you Greg!
Greg
Greg 2018 年 11 月 30 日
Happy to help.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeEnvironment and Settings についてさらに検索

タグ

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by