App Designer にて、Timer オブジェクトのコールバックを使用するにはどうすればよいですか?
Show older comments
App Designer で GUI を構築しています。その中で、Timer オブジェクトを使って、コールバックを設定したいのですが、エラーが発生して実行できません。
Timer オブジェクトは、コールバック間で共有できるように、プライベートプロパティとして設定し、UIFigure の StartFcn で Timer オブジェクトを定義しています。
Timer オブジェクトの TimerFcn コールバックは、App Designer のプライベート関数として記述していますが、Timer をスタートさせると、TimerFcn コールバックとして定義した関数が未定義というエラーが発生します。
(コード抜粋)
methods (Access = private)
function mytimer_fun(app)
% Timer で指定するコールバック関数
disp('Timer!!!!')
end
end
properties (Access = private)
% Timer object 用
update_timer
end
methods (Access = private)
% Code that executes after component creation
function startupFcn(app)
app.update_timer = timer('Period', 1,...
'ExecutionMode', 'fixedSpacing', ...
'TasksToExecute', Inf, ...
'TimerFcn', @mytimer_fun); %コールバック
end
% Button pushed function: STARTButton
function STARTButtonPushed(app, event)
start(app.update_timer)
end
% Button pushed function: STOPButton
function STOPButtonPushed(app, event)
stop(app.update_timer)
delete(app.update_timer)
end
end
(エラーの例)
ERROR: TimerFcn (タイマー 'timer-12') を実行中にエラーが発生
関数 'mytimer_fun' (タイプ'timer' の入力引数) が未定義です。
Accepted Answer
More Answers (0)
Categories
Find more on App Designer を使用したアプリ開発 in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!