Add rows to a table in a parfor loop

19 ビュー (過去 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 Center および File ExchangeData Type Identification についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by