Error with timer TimerFcn

6 ビュー (過去 30 日間)
Happy PhD
Happy PhD 2019 年 10 月 22 日
編集済み: Sourabh Kondapaka 2020 年 11 月 4 日
Hi, am using an timer to plot my camera onto UIAxes. I am getting error everytime I stop the timer.
I am getting the error text below, were the i value in "timer-i" changes everytime.
Error while evaluating TimerFcn for timer 'timer-19'
Matrix dimensions must agree.
when I am using the following code
function CreatePlotTimer(app)
app.timerPlot = timer;
app.timerPlot.StartDelay=1;
app.timerPlot.ExecutionMode='singleShot';
app.timerPlot.TimerFcn = @(~, ~)PlotFunction(app);
end
I am calling the Timer at this location:
if strcmp(get(app.ButtonCamera,'Text'),'Start Camera')
start(app.timerPlot)
set(app.ButtonCaptureImages,'Enable','on');
set(app.ButtonCamera,'Text','Stop Camera') % sets button to 'Stop Camera'
else
%%Camera is off. Change button Text and 'start camera'.
stop(app.timerPlot)
CreatePlotTimer(app);
set(app.ButtonCaptureImages,'Enable','off');
set(app.ButtonCamera,'Text','Start Camera') % sets button to 'Start Camera'
end
Anyone knows what is going on?
Many thanks
  1 件のコメント
Guillaume
Guillaume 2019 年 11 月 1 日
As the error message tells you, the problem is with the TimerFcn PlotFunction which clearly does something with two matrices that don't have the same dimension. Unfortunately, you haven't shown us the code of that function.

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

回答 (2 件)

Mohammad Sami
Mohammad Sami 2019 年 11 月 1 日
This might be an error from your PlotFunction. I suggest you place a debug point in your PlotFunction and then run the app to see where the error comes from.

Sourabh Kondapaka
Sourabh Kondapaka 2020 年 11 月 4 日
編集済み: Sourabh Kondapaka 2020 年 11 月 4 日
The reason for the i value of the "timer-i" keeps changing is because everytime you run the app, you are creating a new timer.
To avoid this, in the createPlotTimer() function, you can add the following before creating a new timer:
function CreatePlotTimer(app)
%Below line finds all active timer's in memory and deletes them.
delete(timerfind);
app.timerPlot = timer;
app.timerPlot.StartDelay=1;
app.timerPlot.ExecutionMode='singleShot';
app.timerPlot.TimerFcn = @(~, ~)PlotFunction(app);
end
Refer the documentation here for more information on timers.
About the error :
Matrix dimensions must agree.
Please try the approaches suggested by Guillaume and Mohammad Sami. If the issue is still not resolved, please upload the code of PlotFunction() and also 2 sample matrices which get passed to it as input arguments.

カテゴリ

Help Center および File ExchangeStartup and Shutdown についてさらに検索

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by