create periodic tasks set

2 views (last 30 days)
joy
joy on 12 Jan 2014
Edited: Amit on 12 Jan 2014
Hi,
I want to create a set of periodic task sets with different period and execution time.I need to generate a code template where if i give a period and execution time then the tasks set would be created..
tasks set would be consists of few nested for loops...i think
for(;;)
{
for(;;)
{
}
}
this are execution time
then
sleep()
so, is it the right approach to do so?...I think execution time would be the time taken to execute for loops and period will be execution time of for loops+sleep time.
any suggestions?

Answers (1)

Amit
Amit on 12 Jan 2014
Edited: Amit on 12 Jan 2014
Lets say you have execution time and period in vector A and B, respectively. Then you might do something like this:
for i = 1:numel(A)
t_in = cputime;
while((cputime - t_in) <= A(i))
_Do Your Thing_
end
pause(B(i)-A(i));
end
Just want to add that calculating while condition will take some time as well, thus the do your thing will be executed for slightly lesser time than actual execution time.

Categories

Find more on Programming in Help Center and File Exchange

Tags

No tags entered yet.

Community Treasure Hunt

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

Start Hunting!