Add rows to a table in a parfor loop
조회 수: 10 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
답변 (1개)
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)
댓글 수: 3
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'})
참고 항목
카테고리
Help Center 및 File Exchange에서 Parallel for-Loops (parfor)에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!