Filter löschen
Filter löschen

Help with making parfor loop work

5 Ansichten (letzte 30 Tage)
Quy
Quy am 19 Mär. 2024
Kommentiert: Edric Ellis am 20 Mär. 2024
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

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 19 Mär. 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 Kommentar
Edric Ellis
Edric Ellis am 20 Mär. 2024
This is correct. You will also need to move the computation width(symTable) to before the parfor loop. The same applies to asymTable.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Parallel for-Loops (parfor) finden Sie in Help Center und File Exchange

Produkte


Version

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by