Pre-built functions suddenly became undefined in app designer?

10 views (last 30 days)
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?

Answers (1)

Walter Roberson
Walter Roberson on 17 Mar 2023
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 Comments
Walter Roberson
Walter Roberson on 29 Mar 2023
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 on 30 Mar 2023
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.

Sign in to comment.

Categories

Find more on Interactive Control and Callbacks in Help Center and File Exchange

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!