Read data acquired by hardware
a single input scan from all input channels on the DataAcquisition, and returns a timetable
scanData = read(
reads a span of input scans from the DataAcquisition interface, and returns a timetable to
scanData = read(
scanData. You can specify
span as a duration, a
number of scans, or
If the DataAcquisition is not running and has no acquired data, the DataAcquisition starts a foreground finite acquisition to read the requested number of scans. MATLAB is blocked until the acquisition and read are complete.
If the DataAcquisition is running when you call this function, it reads data already acquired, if necessary waiting until the specified number of scans are available. MATLAB is blocked until the acquisition and read are complete. This is typical when
startis called to run a background acquisition prior to calling
If the DataAcquisition is not running but has acquired data from a previous run, it reads the specified number of scans or all the data, whichever is less.
performs the specified read, and returns a timetable to
triggerTime] = read(___)
scanData and scan
trigger time to
triggerTime as a datetime.
performs the specified read, and returns an M-by-N matrix of doubles to
scanData = read(___,"OutputFormat","Matrix")
scanData, where M is the number of scans and N is the number of input
channels. Each column contains the data from one channel.
performs the specified read and returns the scan timestamps to
triggerTime] = read(___,"OutputFormat","Matrix")
as an M-by-1 vector of doubles representing the relative time in seconds after the first
scan. The rows of the
timeStamp vector correspond to the rows of the
scanData matrix. The scan trigger time is returned to
triggerTime as a datenum double.
Read a Single Scan
Without specifying a duration or number of scans, the
read function acquires a single on-demand scan on all
d = daq("ni") addinput(d,"Dev1",1,"Voltage"); % add more channels as needed scanData = read(d)
data = timetable Time Dev1_ai1 _____ ________ 0 sec -1.9525
Initiate a Foreground Acquisition
If there is no data available to be read from the device, the
read function initiates a foreground acquisition, blocking MATLAB
d = daq("ni"); ch = addinput(d,"Dev1",1:2,"Voltage")
ch = Index Type Device Channel Measurement Type Range Name _____ ____ ______ _______ ________________ __________________ __________ 1 "ai" "Dev1" "ai1" "Voltage (Diff)" "-10 to +10 Volts" "Dev1_ai1" 2 "ai" "Dev1" "ai2" "Voltage (Diff)" "-10 to +10 Volts" "Dev1_ai2"
Read five scans of data on all channels.
scanData = read(d,5)
scanData = 5×2 timetable Time Dev1_ai1 Dev1_ai2 _________ ________ ________ 0 sec 0.1621 0.62579 0.001 sec 0.42124 0.56955 0.002 sec 0.51069 0.56002 0.003 sec 0.54193 0.56166 0.004 sec 0.55377 0.56396
Read 5 milliseconds of data on all channels.
d.Rate = 1000; scanData = read(d,seconds(0.005))
scanData = 5×2 timetable Time Dev1_ai1 Dev1_ai2 _________ ________ ________ 0 sec 0.2259 0.33278 0.001 sec 0.28871 0.31699 0.002 sec 0.3068 0.31633 0.003 sec 0.3137 0.31929 0.004 sec 0.31732 0.32028
You can also read the data into arrays of double values. Five scans on two channels results in a 5-by-2 matrix, with a column for each channel.
scanData = read(d,5,"OutputFormat","Matrix")
scanData = 0.0424 0.0644 0.0572 0.0621 0.0605 0.0638 0.0618 0.0641 0.0631 0.0648
Read Data from a Background Acquisition
When a background acquisition is initiated with the
start function, use
read to import the
d = daq("ni"); ch = addinput(d,"Dev1",1:2,"Voltage") start(d,"NumScans",5)
Background operation has started. Background operation will stop after 0.005 s. To read acquired scans, use read.
scanData = read(d,"all")
scanData = 5×2 timetable Time Dev1_ai1 Dev1_ai2 _________ ________ ________ 0 sec 0.012466 0.023977 0.001 sec 0.019373 0.023319 0.002 sec 0.021017 0.02299 0.003 sec 0.021346 0.02299 0.004 sec 0.022661 0.023648
d — DataAcquisition interface
DataAcquisition interface, specified as a
object, created using the
d = daq()
span — Length of read operation
duration | double
Length of read operation, specified as a duration or double. If this is a duration type, it specifies the time duration of acquisition; if a double, it specifies the number of scans.
scanData — Input scan data from the device
timetable | double
Input scan data from the device, returned as a timetable or matrix of doubles,
depending on the
The time stamp for each scan in the timetable is a duration, relative to the trigger
time. You can access the scan trigger time in the timetable property
scanData.Properties.CustomProperties.TriggerTime, returned as a
triggerTime — Time that acquisition began
datetime | datenum double
Time that acquisition began, returned as a datetime if
'Timetable' (default), or as a
information is also available as a datetime value in the timetable property
timeStamp — Times of scan acquisitions
Times of scan acquisitions, returned as a matrix of doubles. Each value represents
relative time in seconds after the first scan. This argument is returned only when
OutputFormat is specified as
Introduced in R2020a