Azzera filtri
Azzera filtri

How can I reduce minimum wait() time?

14 visualizzazioni (ultimi 30 giorni)
gujax il 20 Gen 2023
Risposto: Yoga il 10 Mar 2023
I am using wait(obj,state,time-out) minimum timeout is 0.01. If I use any value below 0.01, it defaults to 0.01 seconds. Is there any way I can change this functionality to reduce this to 0.001 seconds or less?
  3 Commenti
gujax il 20 Gen 2023
Modificato: gujax il 20 Gen 2023
What decides this minimum time? Is it the operating system or Matlab? So if my object function gets processed faster than 1 msec, is wait command not going to return Matlab for further commands to be processed until the end of 1 ms? How can I reduce the wait time further? What other methods exists?

Accedi per commentare.

Risposta accettata

Yoga il 10 Mar 2023
Hi @gujax!
The reason is that Windows task scheduler resolution is the order of 15 ms in some recent versions. So it takes a bit of work arounds to actually get this task done.
I see two options. Let's call them the looping option and the native option. The first is just using a while loop to check if your desired time to wait is already reached. You can do this with MATLAB's stopwatch timer tic and toc. This is the normal time (not the CPU-time). As you are writing a loop, which runs at maximum speed, you might encounter a high CPU-usage but this should be OK if it is only for a couple of milliseconds.
%% looping
% desired time to wait
dt_des = 0.001; % 1 ms
% initialize clock
t_st = tic;
% looping
while toc(t_st) < dt_des
% read clock
The native option is using pause (make sure that you have enabled it once with pause('on')). I assumed from your question that this does not always work -- however, it does on my system (R2019b, windows 10).
%% use pause()
The results of both are -
Elapsed time is 0.001055 seconds.
Elapsed time is 0.001197 seconds.
It's not too accurate but you might get better results if you tune the numbers on your PC.

Più risposte (0)


Scopri di più su Programming in Help Center e File Exchange





Community Treasure Hunt

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

Start Hunting!

Translated by