Add rows to a table in a parfor loop

조회 수: 20 (최근 30일)
David Santos
David Santos 2021년 4월 12일
댓글: David Santos 2021년 4월 16일
Hi,
I'm trying to add a row to a Table inside each iteration of a parfor loop, simplified would be something like this:
T=table;
base='/Volumes/Cortegada/AUDIOS'; %Base directory of the audios to read an process
for m=1:length(months)
days=dir(strcat(base,months{m}));
days=days(3:end-1);%
for d=1:length(days)
files=dir(strcat(base,months{m},'/',days(d).name,'/*.wav'));
parfor f=1:length(files)
%Each month and day folder has a different number of files
[x,fs]=audioread(strcat(base,months{m},'/',days(d).name,'/',files(f).name));
%% Some processing with some OUTPUTVARIABLES
temp=table(OUTPUTVARIABLES);
T=[T;temp];
end
end
end
save('T.mat','T');
But it gives me the error:
{ Error using table (line 245)
Transparency violation error.
See Parallel Computing Toolbox documentation about Transparency
}
Any clues on how to solve it? I can accessto the exact table position because there each month/day folder has a different number of audio files
All the best

답변 (1개)

Edric Ellis
Edric Ellis 2021년 4월 14일
편집: Edric Ellis 2021년 4월 16일
This problem should have been fixed in R2019b (please let me know if you're using a later version and things are not working). It might work to explicitly specify the 'VariableNames' for your table, like this:
T = table();
parfor i = 1:4
p = rand(); q = datetime();
temp = table(p,q,'VariableNames', {'p', 'q'});
T = [T; temp];
end
disp(T)
p q _______ ____________________ 0.95376 16-Apr-2021 08:13:32 0.62206 16-Apr-2021 08:13:32 0.71322 16-Apr-2021 08:13:32 0.69861 16-Apr-2021 08:13:32
  댓글 수: 3
Edric Ellis
Edric Ellis 2021년 4월 16일
It might be better still to preallocate the table to the correct size, i.e.
T = table(zeros(totalRows,1), zeros(totalRows,1), 'VariableNames', {'p', 'q'})
David Santos
David Santos 2021년 4월 16일
Thanks

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

카테고리

Help CenterFile Exchange에서 Data Type Identification에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by