Say we have a call-back timer function call_time(obj, event). I want to know the elapsed time (delt_time) during the execution of timer function once it is started. Furthermore, I want to use that elapsed time to decide if the function will be continued executing or be terminated (say delt_time > 60s). I want the timer function to determine the running time concurrently. By doing this way, the code knows when to terminate the program once it reaches to the threshold. Actually, I have asked a couple of similar questions on the basis of different ways that I have tried. But no answers yet.
Now I've tried
function call_time(obj, event)
event_time = event.Data.time;
event_time = event.Data.time - event_time;
while event_time < 60
%execute commands
end
if event_time > 60
%terminate execution
end
end
But it does not work.Below is how I call the timer function.
TimerHandle = timer;
TimerHandle.StartFcn = @(~,thisEvent)disp([thisEvent.Type ' executed '...
datestr(thisEvent.Data.time,'dd-mmm-yyyy HH:MM:SS.FFF')]);
TimerHandle.TimerFcn = @call_time;
TimerHandle.StopFcn = @TimerCleanup;
TimerHandle.period = 10;
TimerHandle.ExecutionMode = 'fixedRate';
start(TimerHandle);
I also tried the way that Tom suggested. But not working as well.
function call_time(obj, event)
event_time = event.Data.time;
delta_time = event.Data.time - event_time;
while delta_time < 60
%execute commands
delta_time = event.Data.time - event_time;
fprintf('Elapsed %.2f sec\n', delta_time);
end
if delta_time > 60
%terminate execution
end
end