main content

write timetable data to tdms-凯发k8网页登录

this example shows how to write timetable data in various time channel layouts from matlab® to a tdms-file.

for this example, you have measurents of revolution and electrical current of a circular saw in a scenario where it stops on detecting contact with skin.

load the data to workspace.

load("sawstopper.mat")
whos
  name                       size             bytes  class        attributes
  circular_saw_data      23572x2             378432  timetable              
filenametcnone = "sawstopper_none.tdms";
filenametcsingle = "sawstopper_single.tdms";
channelgroup = "circular saw data";

write timetable without a time channel

on specifying timechannel as "none", the start time and time step are added as properties of the channel. this time channel layout can be used only with a timetable that is regular in time, that is, with uniform time steps.

tdmswrite(filenametcnone, circular_saw_data, channelgroupname=channelgroup, timechannel="none");
info = tdmsinfo(filenametcnone);
info.channellist
ans=2×8 table
    channelgroupnumber     channelgroupname      channelgroupdescription         channelname         channeldescription    unit    datatype    numsamples
    __________________    ___________________    _______________________    _____________________    __________________    ____    ________    __________
            1             "circular saw data"              ""               "revolutions (1/min)"            ""             ""     "double"      47144   
            1             "circular saw data"              ""               "current (a)"                    ""             ""     "double"      47144   

the channel names in the tdms-file map to the original timetable variable names.

use the tdmsreadprop function to inspect the start time (wf_start_time) and time step (wf_increment) of the data.

channel = info.channellist.channelname{1};
prop = tdmsreadprop(filenametcnone, channelgroupname=channelgroup, channelname=channel)
prop=1×7 table
            name             description    unit_string            wf_start_time            wf_start_offset    wf_increment    wf_samples
    _____________________    ___________    ___________    _____________________________    _______________    ____________    __________
    "revolutions (1/min)"        ""             ""         2022-04-19 14:18:32.304446999           0             2.8e-06         23572   

read the data from the tdms-file and visually analyze the data using a stacked plot.

stackedplot(tdmsread(filenametcnone, timestep=seconds(prop.wf_increment)));

write timetable with a time channel

by default, the time channel layout is timechannel="single", which means a time channel is created that contains a timestamp for every sample. typically this time channel layout is useful when writing measurments that are irregular in time.

tdmswrite(filenametcsingle, circular_saw_data, channelgroupname=channelgroup, timechannel="single");

inspect the contents of the file. see that a time channel called "time" is created, which is derived from the time column of the original timetable.

info = tdmsinfo(filenametcsingle);
info.channellist
ans=3×8 table
    channelgroupnumber     channelgroupname      channelgroupdescription         channelname         channeldescription    unit     datatype      numsamples
    __________________    ___________________    _______________________    _____________________    __________________    ____    ___________    __________
            1             "circular saw data"              ""               "time"                           ""             ""     "timestamp"      47144   
            1             "circular saw data"              ""               "revolutions (1/min)"            ""             ""     "double"         47144   
            1             "circular saw data"              ""               "current (a)"                    ""             ""     "double"         47144   

read the data from the tdms-file, and visually analyze the data using a stacked plot with the time channel as the x-axis.

stackedplot(tdmsread(filenametcsingle, channelgroupname=channelgroup, rowtimes="time"));

网站地图