Resolve readChannelGroups out of Bounds when combining multiple .tdms files

조회 수: 7 (최근 30일)
I have multiple tdms files which I am trying to combine into one using the information available at https://uk.mathworks.com/help/daq/example-merge-multiple-tdms-files.html
When I use this code I get the following error:
readChannelGroups out of Bounds. startIndex(0) + readSize(52417) <= max(numSamplesAcrossChannelGroups)(52276)
From this I gather that there is a limit on the number of rows that can be read, which has been set to 52276. This is the number of rows in the first file in the DataStore. The code runs until it meets a file larger than the first, with 52417 rows.
I tried to remedy this by setting tdmsDatastore ReadSize to 51000 but then I get this error:
readChannelGroups out of Bounds. startIndex(51000) + readSize(1417) <= max(numSamplesAcrossChannelGroups)(52276)
Is there a way I can combine multiple tdms files into one tdms file where it doesn't matter if the files are different lengths?
Here is my full code. If anyone has a suggestion as to how to share the tdms data (or minimal data) in a sensible way then it is welcome!
foldername = uigetdir();
% move up one folder by removing the last bit of the foldername and
% assigning that to variable called "f"
f = foldername(1:end-10);
cd(f);
id = foldername(end-8:end); % new filename = final 9 chars of folder name
newfilename = [id '.tdms'];
ds = tdmsDatastore(foldername, ReadSize = "file");
data = readall(ds);
tdmswrite(newfilename, data);
while(hasdata(ds))
data = read(ds); %read one file.
tdmswrite(newfilename, data);
end
clear

채택된 답변

Aylin
Aylin 2023년 2월 7일
Hello Eleanor, this is likely to be a bug in tdmsDatastore. I have forwarded this to the tdmsDatastore developers.
As a workaround, can you replace this loop:
ds = tdmsDatastore(foldername, ReadSize="file")
while(hasdata(ds))
data = read(ds)
tdmswrite(newfilename, data);
end
With something like this?
fileSet = matlab.io.datastore.FileSet(foldername, FileExtensions=".tdms");
while(fileSet.hasNextFile())
data = tdmsread(fileSet.nextfile().Filename)
tdmswrite(newfilename, data);
end
I hope this helps!
Rylan
  댓글 수: 1
Eleanor Hassan
Eleanor Hassan 2023년 2월 7일
Thank you so much Rylan! This has completely resolved my problem.
For anyone looking in the future, here is the entirety of the working code:
foldername = uigetdir();
f = foldername(1:end-10);
cd(f);
id = foldername(end-8:end)
newfilename = [id '.tdms'];
fileSet = matlab.io.datastore.FileSet(foldername, FileExtensions=".tdms");
while(fileSet.hasNextFile())
data = tdmsread(fileSet.nextfile().Filename)
tdmswrite(newfilename, data);
end
clear

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 TDMS Format Files에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by