waitfor(rate) pauses execution until
the code reaches the desired execution rate. The function accounts for the time
that is spent executing code between waitfor calls.
Start a loop using the rateControl object inside to control the loop execution. Reset the object prior to the loop execution to reset timer. Print the iteration and time elapsed.
reset(r)
for i = 1:10
time = r.TotalElapsedTime;
fprintf('Iteration: %d - Time Elapsed: %f\n',i,time)
waitfor(r);
end
Iteration: 1 - Time Elapsed: 0.002094
Iteration: 2 - Time Elapsed: 1.001134
Iteration: 3 - Time Elapsed: 2.001454
Iteration: 4 - Time Elapsed: 3.001284
Iteration: 5 - Time Elapsed: 4.002086
Iteration: 6 - Time Elapsed: 5.000855
Iteration: 7 - Time Elapsed: 6.000291
Iteration: 8 - Time Elapsed: 7.000683
Iteration: 9 - Time Elapsed: 8.000590
Iteration: 10 - Time Elapsed: 9.000642
Rate object, specified as a handle. This object
contains the information for the desired rate and other information about
the execution. See rateControl (Navigation Toolbox) for more information.
Number of missed task executions, returned as a scalar. waitfor returns the number of times the task was missed in
the Rate object based on the
LastPeriod time. For example, if the desired rate is
1 Hz and the last period was 3.2 seconds, numMisses
returns 3.
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window.
Web browsers do not support MATLAB commands.
Seleziona un sito web
Seleziona un sito web per visualizzare contenuto tradotto dove disponibile e vedere eventi e offerte locali. In base alla tua area geografica, ti consigliamo di selezionare: .
Puoi anche selezionare un sito web dal seguente elenco:
Come ottenere le migliori prestazioni del sito
Per ottenere le migliori prestazioni del sito, seleziona il sito cinese (in cinese o in inglese). I siti MathWorks per gli altri paesi non sono ottimizzati per essere visitati dalla tua area geografica.