Repetitive value arising in for loop

1 vue (au cours des 30 derniers jours)
Amit Chakraborty
Amit Chakraborty le 13 Déc 2021
This is small part of my code. I use a parfor loop here which is required for my project.
There are 60 different types of angle. But in my following code insted of taking all 60 types of diferent angle it is taking only 1 angle( the 60th poistion angle ). As result I am getting only one value for "a" and that repreated for the size of Npixels which is wrong. Can any one help me to tackle this problem?
If you run the code and see the : "Cords" variable your will find the "a" is repeated over the size of Npixels .
CODE::::::
Nangles = 60; % Total Angles
Nvoxels = 64^3 ;
Npixels = 256*256;
startPhi = 0;
endPhi = 354;
zs = 1100;
zd = -400;
FOV= 460;
xv = FOV/2 ;
yv = FOV/2;
zv = FOV/2;
Nx = nthroot(Nvoxels,3);
Ny = nthroot(Nvoxels,3);
Nz = nthroot(Nvoxels,3);
d = FOV/Nx;
dz = d;
theta = deg2rad(90);
Phi= deg2rad(linspace(startPhi,endPhi,Nangles));
B= [xv+(-1).*zs.*sin(theta),yv,zv+zs.*cos(theta),1];
Kai= repmat(B(:,1),Npixels,1);
Shai = repmat(B(:,2),Npixels,1);
G = repmat(B(:,3),Npixels,1);
sourceCords = [Kai,Shai,G];
%% TEST
IntersectionPts_Global = zeros((Npixels),4);
theta = deg2rad(90);
Phi= deg2rad(linspace(startPhi,endPhi,Nangles));
for k = 1:Nangles
phi = Phi(k);
parfor i = 1:Npixels
kai = Kai(i);
shai = Shai(i);
g = G(i);
a =(zd+zv.*cos(phi+theta)+(-1).*xv.*sin(phi+theta)).*(g+zs+zv.*cos(phi+theta)+(-1).*xv.*sin(phi+theta)).^(-1).*(xv+kai.*cos(phi+theta)+(-1).*(g+zs).*sin(phi+theta));
b=0;
c=0;
InterPts_Global = [a,b,c,ones(length(a),1)];
IntersectionPts_Global(i,:) = InterPts_Global;
end
Cords = squeeze(IntersectionPts_Global(:,1:3));
end

Réponse acceptée

Raymond Norris
Raymond Norris le 13 Déc 2021
Please edit your posting so that it displays your code in CODE mode.
This is not a parfor issue, you'd get the same results with for-loop as well. Just to be clear, should
Cords =
be
Cords(:,:,k) =

Plus de réponses (0)

Catégories

En savoir plus sur Parallel for-Loops (parfor) dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by