Pre-built functions suddenly became undefined in app designer?
2 次查看(过去 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?
0 个评论
回答(1 个)
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
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
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 Center 和 File Exchange 中查找有关 Interactive Control and Callbacks 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!