Correct error in parfor loop

1 次查看(过去 30 天)
I am working on a parfor loop in MatLab R2021b, shown below. But there are errors: Valid indices for 'Time_h1' and 'HD_Top' are restricted in PARFOR loops. I would like to how to solve this issue? Thanks.
parfor j = 1:nk2
if abs(ID_sat) < 1e-5
T_mesh(nt,j) = 11;
Time_h1 (1:11,j) = 0:t_final/10:t_final; % error: restricted in PARFOR loops
HD_Top (1:11,j) = 0; % error: restricted in PARFOR loops
else
...
end
end

采纳的回答

Walter Roberson
Walter Roberson 2022-3-10
parfor j = 1:nk2
if abs(ID_sat) < 1e-5
T_mesh(nt,j) = 11;
h1 = Time_h1(:,j);
HT = HD_top(:,j);
h1(1:11) = 0:t_final/10:t_final;
Time_h1(:,j) = h1;
HT(1:11) = 0;
HD_Top(:,j) = HT;
else
...
end
end
  4 个评论
Walter Roberson
Walter Roberson 2022-3-10
When you assign to an array that is indexed by a parfor variable, each index has to be either scalar or the : operator; when you read from an array that is indexed by a parfor variable, each index has to be either scalar or the : operator.
t1 = Time_h1(:,j); %okay because it uses :
t1(1:T_mesh00) = Surface_flux(1:T_mesh00,1); %okay because it is not indexed by j
Time_h1(:,j) = t1; %okay because it uses :

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by