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?

 采纳的回答

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

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Data Acquisition Toolbox Supported Hardware 的更多信息

产品

版本

R2025b

Community Treasure Hunt

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

Start Hunting!

Translated by