合并多个TDMS-Files
This example shows how to merge multiple TDMS-files by appending their data into a single TDMS-file.
在本例中,将转轴的振动数据记录到tdms文件的集合中。目标是读取每个文件并将其数据合并到一个聚合tdms文件中进行分析。您可以通过创建单独的通道组或将数据附加到单个通道组来合并数据。这个例子展示了两种方法。
fileMultipleChannelGroup =“RotatingShaftAnalysis_MultipleChannelGroup.tdms”;fileSingleChannelGroup =“RotatingShaftAnalysis_SingleChannelGroup.tdms”;
通过创建新的通道组追加数据
Create a datastore with which you can iteratively read the collection of TDMS files in the folderRotatingShaftAnalysis
,一次一个文件。
ds = tdmsDatastore (“RotatingShaftAnalysis”ReadSize =“文件”);
可以通过添加新的通道组将数据写入现有的tdms文件。默认情况下,tdmswrite
函数创建自动递增通道组名。
而(hasdata(ds)) data = read(ds);%读取一个文件。tdmswrite (fileMultipleChannelGroup、数据);结束
在检查写入文件的内容时,可以看到有3个通道组映射到文件夹中的3个文件。
信息= tdmsinfo (fileMultipleChannelGroup);信息。ChannelList
ans =9×8表数据类型NumSamples ChannelGroupNumber ChannelGroupName ChannelGroupDescription ChannelName ChannelDescription单元 __________________ ________________ _______________________ ___________ __________________ ____ ________ __________ 1”ChannelGroup1”“”“脉冲”“”“”“双20000 1”ChannelGroup1“”“”Sensor_X“”“”“”“双20000 1”ChannelGroup1“”“”Sensor_Y“”“”“”“双20000 2“ChannelGroup2”““脉搏”“”“”“双”20000年2 ChannelGroup2“”“”Sensor_X“”“”“”“双20000 2"ChannelGroup2" "" "Sensor_Y" "" "" "Double" 20000 3" ChannelGroup3" "" "Pulse" "" "" "Double" 20000 3" ChannelGroup3" "" "Sensor_X" "" "" "Double" 20000 3" ChannelGroup3" "" "Sensor_Y" "" "" "Double" 20000。
将数据追加到单个通道组
您可以将所有tdms文件中的数据附加到单个通道组中。通过指定特定的通道组名,数据将附加到该通道组。
通道名映射到表变量名,因此数据被追加到通道组中的所有通道。如果表变量不作为通道存在,则向通道组添加一个新通道。
重置(ds);而(hasdata(ds)) tdmswrite(fileSingleChannelGroup, read(ds), ChannelGroupName= .输出说明“数据集”)结束
On inspecting the contents of the file, theNumSamples
的属性ChannelList
增加到3 × 20000,表示数据被追加到文件中。
信息= tdmsinfo (fileSingleChannelGroup);信息。ChannelList
ans =3×8表数据类型NumSamples ChannelGroupNumber ChannelGroupName ChannelGroupDescription ChannelName ChannelDescription单元 __________________ ________________ _______________________ ___________ __________________ ____ ________ __________ 脉冲数据集1”“”“”“”“”“”“双60000 1“数据集”“Sensor_X“”“”“”“双60000 1“数据集”“Sensor_Y“”“”“”“双60000