Filter löschen
Filter löschen

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

3 Ansichten (letzte 30 Tage)
Francisco Pereira
Francisco Pereira am 18 Mai 2022
Bearbeitet: Vatsal am 25 Jan. 2024
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

Antworten (1)

Vatsal
Vatsal am 25 Jan. 2024
Bearbeitet: Vatsal am 25 Jan. 2024
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!

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Produkte


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by