0

I am trying to achieve two things:

  1. Start a function if the current time is an exact 10 seconds multiple and
  2. Run the function in a loop every 10 seconds after that

I have a cronjob on AWS pulling data every 10 seconds. I want my MATLAB function to run specifically once that has been updated (every 10 seconds).

The function takes less than 10 seconds to run. Currently, I am doing:

tic
function
toc
elapsedTime=toc;
pause(10-elapsedTime);

but this dosent seem to be working. On top of that, I want the entire function to start at 1:00:10 (seconds).

I think using Matlab's

format shortg
c = clock
fix(c) 

and some how starting at sec = [0,10,20....,60] would work, but I am not sure how to isolate the seconds from the system clock.

horchler
  • 18,384
  • 4
  • 37
  • 73
mmk88
  • 91
  • 1
  • 6
  • 1
    The [`Timer` class](http://www.mathworks.com/help/matlab/ref/timer-class.html) would be a much better choice for this sort of thing. And what do you specifically mean by "this dosent seem to be working"? Your `tic`/`toc` code seems fine (though it won't be super accurate and there's no need to call `toc` twice unless you want the time printed). Are you showing all of your code? – horchler Nov 27 '15 at 18:15
  • sure, the tic-toc isnt exactly precise, but I read that is unavoidable. – mmk88 Nov 27 '15 at 18:44
  • However, how do i go about starting the function initially at a multiple of 10 seconds in real time ... i.e. I want it to start at 1 PM, 10 Min, and 10 Seconds ..... – mmk88 Nov 27 '15 at 18:45

0 Answers0