Help with making parfor loop work
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Need help making the code below run in parfor loop. The errors are:
"The parfor loop cannot run due to the way symTable is used"
"The parfor loop cannot run due to the way asymTable is used"
freqVec = freqMin:freqStep:freqMax;
fullModes = 1:4;
symTab = ["Frequency" ; "S"+string(fullModes'-1) + " Cp"];
asymTab = ["Frequency" ; "A"+string(fullModes'-1) + " Cp"];
tableTypes = repmat("double",1,fullModes(end)+1);
symTable = table('Size',[length(freqMin:freqStep:freqMax) fullModes(end)+1],'VariableNames', ...
symTab,'VariableTypes',tableTypes);
asymTable = table('Size',[length(freqMin:freqStep:freqMax) fullModes(end)+1],'VariableNames', ...
asymTab,'VariableTypes',tableTypes);
parfor ii = 1:length(freqVec)
currentFreq = freqVec(ii);
symCTR = 1;
asymCTR = 1;
%LOTS OF CODE HERE TO DETERMINE Cp, which is a 2x10 matrix
for modeType = 1:2
if any(CpFin(1,:) ~= 0,2) % store root results into table based on mode.
symTable(ii,1) = {currentFreq};
asymTable(ii,1) = {currentFreq};
for j = 1:size(CpFin,2)
if modeType == 1
if symCTR > width(symTable)-1
continue
elseif CpFin(1,j) == 0
continue
elseif round(CpFin(1,j)) == Cs || round(CpFin(1,j)) == Cl
continue
end
symTable(ii,symCTR+1) = {CpFin(1,j)};
symCTR = symCTR + 1;
else
if asymCTR > width(asymTable)-1
continue
elseif CpFin(1,j) == 0
continue
elseif round(CpFin(1,j)) == Cs || round(CpFin(1,j)) == Cl
continue
end
asymTable(ii,asymCTR+1) = {CpFin(1,j)};
asymCTR = asymCTR + 1;
end
end
end
end
end
0 commentaires
Réponse acceptée
Walter Roberson
le 19 Mar 2024
First of all, you are permitted only one assignment into a variable indexed by your parfor loop. Having
symTable(ii,1) = {currentFreq};
and
symTable(ii,symCTR+1) = {CpFin(1,j)};
is not allowed.
What you effectively have to do is assign into a temporary variable, and then assign the temporary variable to symTable(ii,:)
1 commentaire
Edric Ellis
le 20 Mar 2024
This is correct. You will also need to move the computation width(symTable) to before the parfor loop. The same applies to asymTable.
Plus de réponses (0)
Voir également
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!