Error - assigning variable in parfor-loops - tvirfres.m (BEAR Toolbox)

3 次查看(过去 30 天)
I'm trying to use the ECB's BEAR Toolbox but I'm running into some trouble, perhaps you can assist me.
While using the interface provided by the Toolbox, I'm running the Time Varying General functionality (print 2 and 3 below).
I seem to get an error regarding the parfor-loop (print 1) in file tvirfres.m (in attachment).
There's a similar issue reported (https://www.mathworks.com/matlabcentral/answers/583190-error-in-parallel-for-loops-in-matlab-r2020a). However the solution pruposed here (substitute the variables in the loop for 'jjj') did not seem to solve the problem.
Would you be able to assist in this situation?
Best regards

回答(1 个)

Vatsal
Vatsal 2024-1-25
编辑:Vatsal 2024-1-25
Hi Francisco,
I encountered the error message "Assigning to the for-loop variable 'jj' is not supported in parfor-loops" when running the provided code, which you had previously noted. This error occurs because in MATLAB, you cannot assign a value to the loop variable 'jj' within a parfor loop. The parfor loop is designed for parallel computation, where each iteration should be independent to facilitate the parallel execution by MATLAB without any interdependencies that could lead to conflicts or necessitate synchronization.
I understand that you attempted to resolve the issue by substituting the loop variable 'jj' with 'jjj', but it seems that didn't rectify the problem for you. Upon implementing the same strategy in the code, it appears to have successfully addressed the error on my end. I have updated the variable names within the parfor loop from 'jj' to 'jjj' in lines 257 through 274, ensuring that each iteration remains independent as required for parallel execution.
Here is the revised section of the code:
jjj=1;
while success==1 && jjj<=n
% build column j of the random matrix Q
[qj]=bear.qrandj(n,Zcell{1,jjj},stackedirfmat,Qj);
% obtain the candidate column fj
fj=stackedirfmat*qj;
% check restrictions: first sign restrictions
[success,qj]=bear.checksignres(Scell{1,jjj},qj,fj);
% if 'success' is still equal to 1, also check for magnitude restrictions
if success==1
[success]=bear.checkmagres(Mcell{1,jjj},Mlcell{1,jjj},Mucell{1,jjj},fj);
end
% also, if 'success' is still equal to 1, update Qj by concatenating qj
if success==1
Qj=[Qj qj];
end
jjj=jjj+1;
end
Hope this helps!

类别

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

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by