フィルターのクリア

Help with making parfor loop work

2 ビュー (過去 30 日間)
Quy
Quy 2024 年 3 月 19 日
コメント済み: Edric Ellis 2024 年 3 月 20 日
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

採用された回答

Walter Roberson
Walter Roberson 2024 年 3 月 19 日
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 件のコメント
Edric Ellis
Edric Ellis 2024 年 3 月 20 日
This is correct. You will also need to move the computation width(symTable) to before the parfor loop. The same applies to asymTable.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeParallel for-Loops (parfor) についてさらに検索

製品


リリース

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by