필터 지우기
필터 지우기

Pre-built functions suddenly became undefined in app designer?

조회 수: 3 (최근 30일)
Thomas Hyatt
Thomas Hyatt 2023년 3월 17일
댓글: Jeremy Hughes 2023년 3월 30일
In my application I have buttons that are changing color on press by means of code like this:
function Button_2Pushed(app, event)
app.user_button_sequence = [app.user_button_sequence 2];
stop(timerfind)
but2_timer = timer;
but2_timer.StartDelay = 1;
but2_timer.StartFcn = @(~,thisEvent) toggleColorOn(app,2);
but2_timer.TimerFcn = @(~,thisEvent) toggleColorOff(app,2);
start(but2_timer)
end
And this has been working perfectly fine as I have been developing it.
I have saved, closed, and opened this many times before, and it was fine each time. Today however, upon trying to make the button change color, it tels me that 'stop' is an undefined function for input arguments of type 'double'. If commented out, it says the same thing about 'start' but for objects (which the timer is).
What happened that this issue is suddenly popping up? I searched for other issues like this and ran into comments about running the code:
restoredefaultpath
rehash toolboxcach
but this hasn't fixed anything.
Can anyone share some insight into what happened and why it suddenly stopped working?

답변 (1개)

Walter Roberson
Walter Roberson 2023년 3월 17일
if timerfind() returns empty then it is [] that it returns rather than an empty array of class timer. And stop([]) does not work. You should be using something like
existing_timers = timerfind();
if ~isempty(existing_timers); stop(existing_timers); end
But are you sure you want to stop all other timers and create a new timer, leaving the other ones existing but in stopped state ??
  댓글 수: 7
Walter Roberson
Walter Roberson 2023년 3월 29일
It did eventually end, and does appear to have created all the timers. But timerfind() and timerfindall() are reporting empty even though the timers have ObjectVisibility on
Jeremy Hughes
Jeremy Hughes 2023년 3월 30일
Thanks @Walter Roberson, This is a great analysis. There's no hard limit on the number of timers, but it looks like you've hit the practical limits of how many you can create.
I'm surprised timerfind doesn't return anything. I'll look at that one.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by