Clear Filters
Clear Filters

How do I import specific channels from multiple consecutive tdms files into workspace?

6 views (last 30 days)
Hey there,
I'm trying to import specific channels from multiple tdms files to my MatLab workspace using tdmsDatastore. With the documentation given I can't figure out how to import just specific channels due to a lack of memory.
All tdms files in one folder are from the same measurment, during the measuremnt the data is saved into a single file when reaching 1.5 GB and a new tdms file is created. Multiple sensors are used and eachs ensor saves the data in one channel. For the analysis I'm planning I only need a few channels, which would lower the size of the imported data. I would like to read in and reassemble certain channels of the individual files. Ideally, each channel should be stored in the same struc.
The files are stored in one folder with the same name like the following: folder: "Experimental_data"; files:"Experimental_data_time";"Experimental_data_time_2";"Experimental_data_time_3";... .
How can I do so? I hope anybody can help, so far there aren't many threads on the topic of tdmsDatastore, read, etc.
Thank you very much!

Answers (1)

Harald
Harald on 24 Oct 2023
Hi Philipp,
in the documentation, find the SelectedChannelGroup and SelectedChannels properties.
The doc example shows how to use them, e.g.:
td = tdmsDatastore("C:\data\tdms");
%...
td.SelectedChannelGroup = "Force";
If you have large data and need to work with all channels, you can also use the read command (rather than readall) and control the number of rows imported at a time by setting the ReadSize property.
Best wishes,
Harald
  1 Comment
Philipp Schumann
Philipp Schumann on 25 Oct 2023
Thank you for your answer! In the meantime i used the follwoing code:
path = uigetdir;
folderName = fullfile(string(path));
ds = tdmsDatastore(folderName);
while in var all important channel names I want to extract are stored.
for i = 1:length(ds.Files)
data{i,1} = tdmsread(ds.Files(i), ...
ChannelGroupName = ds.ChannelList.ChannelGroupName(1), ...
ChannelNames = [string(var(1)) string(var(2)) string(var(3))]);
%ChannelNames = ["trigger" "force_upper_tool_chn1_z" "displacement_eddy_current"]);
DATA.Trigger = [DATA.Trigger;table2array(data{i,1}{1,1}(:,1))];
DATA.Kraft_Stempel_z = [DATA.Kraft_Stempel_z;table2array(data{i,1}{1,1}(:,2))];
DATA.Weg = [DATA.Weg;table2array(data{i,1}{1,1}(:,3))];
end
This worked fine for me

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!