Main Content

tdmswrite

Write data to TDMS-file

Description

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

example

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,ChannelGroupNames=chGrpName) specifies an existing channel group to write the data to. When specifying data as a cell array, use a cell array of strings to identify the corresponding channel group names, sequentially mapped by elements.

tdmswrite(___,TimeChannel=timeChan) specifies how measurement time is included in the file when writing data from a timetable. A TimeChannel value of "none" adds the start time and step time to the channel properties. A value of "single" adds a single channel with a timestamp for every measurement. If you are writing data from a regular table, the TimeChannel setting is ignored.

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

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: "ChannelGroup1"

Data Types: char | string | cell

Time channel format layout, specified as a string or character vector with value "single" or "none":

  • 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.

Example: "none"

Data Types: char | string

Limitations

  • TDMS functions are supported on Windows® platforms only.

Version History

Introduced in R2022b