Reduce reduce the number of for loops?

1 visualización (últimos 30 días)
pham
pham el 19 de Nov. de 2017
Respondida: Nicolas Schmit el 20 de Nov. de 2017
I have function.
function G=J(Fleft,Fright,Data)
cxleft=size(Fleft,2);
cxright=size(Fright,2);
cd=size(Data,2);
k=1;
Tmp=zeros(3,cxright*cxleft*cd);
for i=1:cxleft
for j=1:cxright
for t=1:cd
Tmp(1,k)=Fleft(1,i)+Fright(1,j)+Data(1,t);
Tmp(2,k)=(Data(1,t)*Data(2,t)+Fleft(1,i)*Fleft(2,i)+Fright(1,j)*Fright(2,j))/Tmp(1,k);
Tmp(3,k)=((Fleft(1,i)*Fright(1,j)*(Fleft(2,i)-Fright(2,j))^2+Fleft(1,i)*Data(1,t)*(Fleft(2,i)-Data(2,t))^2+Fright(1,j)*Data(1,t)*(Fright(2,j)-Data(2,t))^2)/Tmp(1,k))+Fleft(3,i)+Fright(3,j)+Data(3,t);
k=k+1;
end
end
end
G=Tmp;
How do we reduce the number of for loops?

Respuestas (1)

Nicolas Schmit
Nicolas Schmit el 20 de Nov. de 2017

Categorías

Más información sobre Loops and Conditional Statements 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!

Translated by