App Designer にて、Timer オブジェクトのコールバックを使用するにはどうすればよいですか?
이전 댓글 표시
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' の入力引数) が未定義です。
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 App Designer を使用したアプリ開発에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!