Main Content

tdmswrite

Write data to TDMS file

Since R2022b

Description

With the tdmswrite function you can write table or timetable data to a new or existing TDMS file.

tdmswrite(tdmsfile,tdmsdata) writes data to the specified TDMS file from a table, timetable, or cell array of tables or timetables. Each table is written to the file as a new channel group, automatically incrementing the channel group name with each write.

tdmswrite(tdmsfile,tdmsdata,Name=Value) writes data with additional options such as channel group name and time channel format layout specified by one or more name-value arguments. For example, to write the data to an existing channel group named ChanGrp1, set ChannelGroupNames to "ChanGrp1"

example

Examples

collapse all

Write data to a specified TDMS file. You can use default channel groups or specify channel group names.

Write a table or timetable of data, T, to a new channel group in the TDMS file named sinewave.tdms.

tdmswrite("sinewave.tdms",T)

Write table or timetable of data, T, to a specific channel group in a TDMS file. If the channel group does not exist, it is added to the file.

tdmswrite("sinewave.tdms", T, ChannelGroupNames="MeasuredData")

Write two tables of data to multiple channel groups in a TDMS file.

tdmswrite("sinewave.tdms", {T1,T2}, ChannelGroupNames=["Measurement1" "Measurement2"])

Input Arguments

collapse all

TDMS file name, specified as a string.

For local files, use a full or relative path that contains a file name and extension. You also can specify a file on the MATLAB® path.

Example: "sample332.tdms"

Data Types: char | string

TDMS data, specified as table, timetable, or cell array of tables and timetables. Alternatively, you can specify several tables or timetables as a series of arguments, such as T1,T2,T3.

For a duration timetable, the written start time is 0. When reading this file with tdmsread, the start time is the epoch in the local time zone equivalent to 01/01/1904 00:00:00.00 UTC (using the Gregorian calendar and ignoring leap seconds). For more information, see TDMS File Format Internal Structure.

Data Types: table | timetable | cell

Name-Value Arguments

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Example: tdmswrite("sinewave.tdms", {T1,T2}, ChannelGroupNames=["ChannelGroup1" "ChannelGroup2"], TimeChannel="none")

Channel group name, specified as a string or character vector. Use an array of channel group names when writing multiple tables.

  • If the channel group does not exist in the TDMS file, a new channel group is created.

  • If the channel group exists, data is appended to channels with names matching the table variables. New channels are added to the channel group for table variables not already represented by existing channel names.

Example: tdmswrite("sinewave.tdms", T, ChannelGroupNames="ChannelGroup1")

Data Types: char | string | cell

Time channel format layout, specified as a string or character vector with value "single" or "none". The format specifies how the measurement time is included in the TDMS file when writing data from a timetable. If you are writing data to a TDMS file from a regular table instead of a timetable, the TimeChannel setting is ignored.

  • A value of "single" (default) adds a single channel with a timestamp for every measurement. This is appropriate for timetables with irregular timing, when each measurement has a unique datetime or duration, shared across the channels in the channel group. This Time channel is derived from the Time variable of the input timetable.

  • A value of "none" adds only the start time and step time to the channel properties wf_start_time and wf_increment, respectively. Appropriate for regular timetables with fixed sample rates, this option can reduce the size of the TDMS file.

Note

For better performance when writing data to a TDMS file from a timetable with regular time interval, use TimeChannel="none".

Example: tdmswrite("sinewave.tdms", T, TimeChannel="none")

Data Types: char | string

Version History

Introduced in R2022b