How to solve "parfor cannot be classified" issue?
Mostra commenti meno recenti
Greetings,
I tried to convert my program with nested for-loops to parfor loop and got error "The variable z in a parfor cannot be classified". I read documents about "Troubleshoot Variables in parfor-Loops". But I don't totally understand it and even I tried different ways, the program still does not work.
Which rule I violate ( the slicing or nested for-loops )? And how to solve it, pack it as a function?
function xhat = eGram(Func,ParaVector,X0,scaling,flag)
Tol = 1E-7;
% gramian parameters
n = ParaVector(1);
k = ParaVector(2);
% initialization for T for observability
T(:,:,1) = eye(n,n);
Cm = logspace(log10(0.01),log10(1),5) .';
e = eye(n,n);
s = length(Cm);
r = size(T,3);
xhat = zeros(n,n,r*s);
Ts = 0.1;
nu = 600;
[~,~,Y0] = Func(X0);
if scaling
Y0_ = scale(Y0,Y0,Tol);
else
Y0_ = Y0;
end
for l=1:r
for m=1:s
z = zeros(n,nu*k);
parfor i=1:n % !!! Here said variable z does not use
% apply perturbed initial condition
initvalue = X0 + Cm(m)*T(:,:,l)*e(:,i);
[t,X,Y] = Func(initvalue);
if scaling
Y_ = scale(Y,Y0,Tol);
else
Y_ = Y;
end
if flag==0
for iii = 1:k
z(i,nu*(iii-1)+1:nu*iii) = (Y_(:,iii) - Y0_(1,iii))';
end
else
for iii = 1:k
z(i,nu*(iii-1)+1:nu*iii) = (Y_(:,iii) - Y0_(:,iii))';
end
end
end
chsi = z*z';
xhat(:,:,(l-1)*s+m) = 1/(r*s*Cm(m)^2)*Ts*T(:,:,l)*chsi*T(:,:,l)';
if any(isnan(xhat))
disp(['l is ' num2str(l)]);
disp(['m is ' num2str(m)]);
disp(['i is ' num2str(i)]);
end
end
end
end
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Loops and Conditional Statements in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!