Why does the Data Acquisition Toolbox “read” function return faster than the specified “span” in MATLAB R2025b?

I am using the "read" function from the Data Acquisition Toolbox in MATLAB R2025b to read data from a device. I want to collect data for 3 seconds. The documentation describes a "span" parameter, which can be specified as a duration. When I call "read(dq, seconds(3))", and I notice the call executes for less than 3 seconds when timed using "tic" and "toc". How is this possible?

 Réponse acceptée

It’s possible for “read” to execute for a time shorter than the specified "span" if the data buffer already has data when “read” is called. The example below illustrates this behavior.
dq = daq("ni");
addinput(dq, "Dev1", "ai0", "Voltage");
start(dq, "continuous");
pause(1);
tic;
data = read(dq, seconds(3));
elapsed = toc();
stop(dq);
dataSpan = seconds(max(data.Time) - min(data.Time));
fprintf("Recorded elapsed time: %.3f s\n", elapsed); % ~2.000 s
fprintf("Data time span: %.3f s\n", dataSpan); % ~3.000 s

Plus de réponses (0)

Catégories

En savoir plus sur Data Acquisition Toolbox Supported Hardware dans Centre d'aide et File Exchange

Produits

Version

R2025b

Community Treasure Hunt

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

Start Hunting!

Translated by