Main Content

read

Read data in TDMS datastore

Since R2022a

Description

data = read(tdmsds) reads data from the files in the TDMS datastore tdmds, and returns a cell array of tables or timetables. Each element of the cell array corresponds to a channel group in the datastore file data.

The read function returns a subset of data from the datastore. The size of the subset is determined by the ReadSize property of the datastore object. On the first call, read starts reading from the beginning of the datastore, and subsequent calls continue reading from the endpoint of the previous call. Use reset to read from the beginning again.

The function returns a cell array of tables or a cell array of timetables, depending on the value of the tdmds.RowTimes property. See Read TDMS File Data into Timetables.

example

[data,info] = read(tdmsds) also returns the output argument info, with information and metadata about the extracted data.

example

Examples

collapse all

Read data from a TDMS datastore one file at a time. Set the read size and read the first data set.

tdmsds = tdmsDatastore("C:\data\tdms",ReadSize="file");
data1 = read(tdmsds);

Read the second file and view information about the data.

[data2,info2] = read(tdmsds);
info2
info2 = 
  struct with fields:

    Filename: "C:\data\tdms\Turbine_002.tdms"
    FileSize: 172098
      Offset: 0

By providing a vector of durations, you can read TDMS file data into timetables.

Define a vector of 1000 elements of 1 ms duration. Set up the datastore object to read 1000 records (ReadSize) and return a timetable (RowTimes).

durvec = milliseconds(1:1000);
tdmsds = tdmsDatastore("C:\data\tdms",ReadSize=1000,RowTimes=durvec)
tdmsds = 

  TDMSDatastore with properties:

                   Files: ["C:\data\tdms\Turbine_001.tdms"    "C:\data\tdms\Turbine_002.tdms"    "C:\data\tdms\Turbine_003.tdms"]
             ChannelList: [6×8 table]
    SelectedChannelGroup: [0×0 string]
        SelectedChannels: [0×0 string]
                RowTimes: [0.001 sec    0.002 sec    0.003 sec    0.004 sec    0.005 sec    0.006 sec    0.007 sec    …    ]
                ReadSize: 1000

Read 1000 records from the datastore into timetables.

dd = read(tdmsds)
dd =

  1×3 cell array

    {1000×2 timetable}    {1000×2 timetable}    {1000×2 timetable}

View part of one of the timetables.

dd{1}
ans =

  1000×2 timetable

      Time       Acceleration1    Acceleration2
    _________    _____________    _____________

    0.001 sec       -1.9851                0   
    0.002 sec       -3.9702                0   
    0.003 sec        11.911           1.5521   
    0.004 sec        5.9553          -1.5521   
    0.005 sec        1.9851          -4.6562   
    0.006 sec        5.9553           4.6562   
    0.007 sec        3.9702          -1.5521   
    0.008 sec        3.9702          -4.6562   

        :              :                :      

    0.993 sec        50.656          -469.05   
    0.994 sec        46.686          -475.26   
    0.995 sec         40.73          -472.16   
    0.996 sec         40.73          -462.84   
    0.997 sec        34.775          -461.29   
    0.998 sec        38.745          -472.16   
    0.999 sec        38.745           -464.4   
    1 sec            34.775          -462.84   

	Display all 1000 rows.

Input Arguments

collapse all

TDMS datastore, specified as a TDMSDatastore object.

Example: tdmsds = tdmsDatastore("C:\data\tdms")

Output Arguments

collapse all

Output data, returned as a cell array of tables from the TDMS records.

Information about the data source file, returned as a structure with the following fields:

Filename
FileSize
Offset

The offset field indicates the position of the data in the file.

Limitations

  • TDMS functions are supported on Windows® platforms only.

Version History

Introduced in R2022a

See Also

Functions