Repetitive value arising in for loop
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Amit Chakraborty
el 13 de Dic. de 2021
Editada: Amit Chakraborty
el 13 de Dic. de 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
0 comentarios
Respuesta aceptada
Raymond Norris
el 13 de Dic. de 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) =
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Assembly en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!