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