if there is startat, is there also stopat?

why is there a startat function for timer, but there is none for stopping (such as stopat *if there's any) ?
thank you..

 Accepted Answer

Because it is trivial to write your own?
stopat = @(Timer,stoptime) startat(timer('StartFcn', @(src,evt) stop(Timer)), stoptime);

9 Comments

I voted this, although STARTAT would be trivial to write also.
Also, to be complete, you would want the timer that's created inside to be deleted once it triggers so that you wouldn't have ghost timers lingering around.
Sir Walter,
1.Will i make a separate function for this, or will i just include this to my main function?
2.I used it in my main function, and here went out:
***********************************************************
??? Error using ==> timer.startat at 133
Cannot start timer without specifying a TimerFcn callback
Error in ==>
myMainFcn>@(Timer,stoptime)startat(timer('StartFcn',@(src,evt)stop(Timer)),stoptime)
Error in ==> myMainFcn at 72
stopat(t1, dfinish(1,1));
***********************************************************
"t1" here is my timer function:
t1=timer('TimerFcn', 'kaptur1', 'ExecutionMode', 'FixedRate');
"kaptur1" here is my separate function that captures image using getsnapshot.
"dfinish" here is just array of time string
dfinish={'07:31' '07:33' '07:35' '13:25' '14:55' '16:25' '09:01'... '20:55'};
in my main program, i used startat:
dstart={'07:30' '07:32' '07:34' '12:00' '13:30' '15:00' '18:00'... '19:30'};
startat(t1, dstart(1,1)); %this captures the image at exactly at 07:30AM
%and there's no error in it, unlike in stopat
NOTE: I used stopat, same as how i used startat..but there's the error..
Will i use a separate Timer Callback Function instead of Specifying Callback Functions Directly?
Good point about deleting the timer, Jiro. Okay, I think this might work:
stopat = @(Timer,stoptime) startat(timer('TimerFcn', @(src,evt) [stop(Timer), delete(src)]), stoptime);
This is not designed to work with an array of times though.
Kent, there is no documented ability to startat() at timer at multiple date strings.
i have a for loop that starts the date strings one at a time using startat, and it works.. the only problem is to stop it at specific time for example in dfinish..
i'll try to use your stopat by deleting the timer used suggested by Jiro.
Ahmm..sir Walter, i tried it..and i encountered this new error, it went out before 7.31AM came..
*******************************************************************
??? Error while evaluating TimerFcn for timer 'timer-19'
Error using ==> timer.stop
Too many output arguments.
*******************************************************************
however,still,it started capturing at exactly 7.30AM but does not stop capturing at 7.31AM, instead, it captures on and on..it should stop capturing at 7.31AM..
on the other hand..
together with the program i tested includes this:
******
startat(t1, dstart(1,1)); %kaptur1
stopat(t1, dfinish(1,1));
startat(t2, dstart(1,2)); %kaptur2
stopat(t2, dfinish(1,2));
******
while kaptur1 is continuously capturing, kaptur2 starts capturing at 7.32AM (which is correct)..however, it still didn't stop capturing at 7.33Am. same problem with the kaptur1..this time kaptur1 and kaptur2 are capturing images continuously and does not stop..
i think i made my point.. sorry for being wordy..my apology..
I tried to be clever about combining two commands into one anonymous function. It works more often than not, but this seems to be one of the "not" times.
At the moment I cannot think of a way to get around the problem while still using an anonymous function. Writing the function non-anonymously should be fine:
function stop_and_delete(src,evt,Timer)
stop(Timer);
delete(src);
end
Then
stopat = @(Timer,stoptime) startat(timer('TimerFcn', {@stop_and_delete, Timer}), stoptime);
Sir Walter, it works.. however, this warning went out..
*********************************************************
Warning: One or more timer objects were stopped before
deletion.
*********************************************************
The thing you said "not" times, maybe the result of that.. ^^ .. But still it worked.. thank you.. thumbs up..
@Jiro: Thanks also for the sharing of idea..it was helpful.. Thank you.

Sign in to comment.

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!