Add rows to a table in a parfor loop

10 vues (au cours des 30 derniers jours)
David Santos
David Santos le 12 Avr 2021
Commenté : David Santos le 16 Avr 2021
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

Réponses (1)

Edric Ellis
Edric Ellis le 14 Avr 2021
Modifié(e) : Edric Ellis le 16 Avr 2021
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 commentaires
Edric Ellis
Edric Ellis le 16 Avr 2021
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 le 16 Avr 2021
Thanks

Connectez-vous pour commenter.

Catégories

En savoir plus sur Parallel for-Loops (parfor) dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by