Add rows to a table in a parfor loop

16 Ansichten (letzte 30 Tage)
David Santos
David Santos am 12 Apr. 2021
Kommentiert: David Santos am 16 Apr. 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

Antworten (1)

Edric Ellis
Edric Ellis am 14 Apr. 2021
Bearbeitet: Edric Ellis am 16 Apr. 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 Kommentare
Edric Ellis
Edric Ellis am 16 Apr. 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 am 16 Apr. 2021
Thanks

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Data Type Identification finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by