Preview most recent acquired analog input data


data = peekdata(obj,samples)
data = peekdata(obj,samples,'type')



An analog input object.


The number of samples to preview for each channel contained by obj.


Specifies the format of the extracted data as double (the default) or as native.


An m-by-n matrix where m is the number of samples and n is the number of channels.


data = peekdata(obj,samples) returns the latest number of samples specified by samples to data.

data = peekdata(obj,samples,'type') returns the number of samples specified by samples in the format specified by type for each channel contained by obj. If type is specified as native, the data is returned in the native data format of the device. If type is specified as double (the default), the data is returned as doubles.


Create the analog input object ai for a National Instruments® board, add eight input channels, and configure ai for a two-second acquisition.

ai = analoginput('nidaq','Dev1');
ai.SampleRate = 2000
ai.SamplesPerTrigger = 4000

After issuing the start function, you can preview the data.

data = peekdata(ai,100);

peekdata returns 100 samples of data for each of the eight channels added to the object. If 100 samples are not available, then whatever samples are available will be returned and a warning message is issued. The data is not removed from the data acquisition engine.

More About

expand all


More About Using peekdata

  • Unlike getdata, peekdata is a nonblocking function that immediately returns control to the MATLAB workspace. Because peekdata does not block execution control, data might be missed or repeated.

  • peekdata takes a "snapshot" of the most recent acquired data and does not remove samples from the data acquisition engine. Therefore, the SamplesAvailable property value is not affected when peekdata is called.

Rules for Using peekdata

  • You can call peekdata before a trigger executes. Therefore, peekdata is useful for previewing data before it is logged to the engine or to a disk file.

  • In most cases, you will call peekdata while the device object is running. However, you can call peekdata once after the device object stops running.

  • If samples is greater than the number of samples currently acquired, all available samples are returned with a warning message stating that the requested number of samples were not available.

  • If you start an analog input object and LoggingMode is Memory or Disk&Memory, extract the acquired data from the engine, using getdata. You can also flush it out using flushdata. If you do not extract or flush data, you receive a DataMissed event when the amount of acquired data reaches the MaxBytes limit for the object as seen by daqmem. The acquisition then stops.

Was this topic helpful?