main content

read a large tdms-凯发k8网页登录

this example shows how to use a tdms datastore to read data from a large tdms-file into matlab® for analysis.

the example tdms-file contains measurement data of a sine wave amplitude and phase. it also contains a channel group with sporadic events triggered at random times. the example file itself is not large, but is used to show the techniques for handling a large file.

you can use a tdms datastore object to read a large tdms-file into matlab by iteratively reading available chunks of data. the size of the data in each iteration might depend on a time interval of interest, an absolute number of samples, or other group definition.

define the datastore and view its channel information

given the name of the tdms-file, use the function to create a tdms datastore object for a specified read size and channel group.

filename = "sinewavewithevents.tdms";
readsize = 1000;
ds = tdmsdatastore(filename, readsize=readsize, selectedchannelgroup="measured data");

examine the data store channel list to identify the channel group and channel names of interest.

ds.channellist
ans=4×8 table
    channelgroupnumber    channelgroupname    channelgroupdescription       channelname       channeldescription    unit     datatype      numsamples
    __________________    ________________    _______________________    _________________    __________________    ____    ___________    __________
            1             "measured data"               ""               "amplitude sweep"            ""             ""     "double"         11000   
            1             "measured data"               ""               "phase sweep"                ""             ""     "double"         11000   
            2             "events"                      ""               "time"                       ""             ""     "timestamp"          5   
            2             "events"                      ""               "description"                ""             ""     "string"             5   

read data into matlab

loop through the file to read 1000 samples at a time, until the end of the file. the datastore read size and selected channel group were defined when the datastore ds was created above with the tdmsdatastore function. the function is constrained by these parameters. use the function if you do not know the number of iterations required.

while(hasdata(ds))
    data = read(ds);     
        % this loop overwrites the last iteration data, 
        % so any analysis of individual data or cumulative
        % reduction operations must happen inside the loop.
end

visualize the most recent chunk of data

you can visualize the last 1000 samples of data using a stacked plot on the first channel group.

stackedplot(data{1});

examine event data

read and display the channel group containing the event data. this requires redefining the datastore object with tdmsdatastore function for that channel group. assuming it is not a large set of data, you can use the function to retrieve it all at once.

ds = tdmsdatastore(filename, selectedchannelgroup="events");
data = readall(ds);
data{1}
ans=5×2 table
                time                  description 
    _____________________________    _____________
    2022-01-12 22:21:36.058876037    "failure 123"
    2022-01-12 22:21:38.558219909    "failure 123"
    2022-01-12 22:21:40.058685302    "failure 123"
    2022-01-12 22:21:41.558692932    "event 4711" 
    2022-01-12 22:21:44.559547424    "failure 123"
网站地图