user2208454
user2208454

Reputation: 43

How to control timing of the commands (MATLAB)

I have a loop that has a command I want to execute at a specific time, say 3 seconds from now. But I don't want to add a delay because I want my rest of the statements and the loop to execute continuously without delay. Is there any way I can store statements in a buffer to execute at a required time?

Upvotes: 1

Views: 38

Answers (2)

Justin Fletcher
Justin Fletcher

Reputation: 2409

Have you tried tic and toc? Like this:

tic
executeFlag = 1;
while(1)                                          % Your loop here.
    if (toc > 3) && (executeFlag)
        timedThing();                             % The thing to run on a timer.
        executeFlag = 0;
    end 
    everythingElse();                             % Everything else you need to do.
end

It's not pretty, but it will do the job. You can remove the executeFlag if you want the timed thing to run after a certain time.

Let me know if this doesn't do it for you, and I'll take another shot at it.

Upvotes: 0

Daniel
Daniel

Reputation: 36710

You need to set up a timer object. The "Display message using Timer"-Example shows exactly what you need.

Upvotes: 1

Related Questions