Reduce reduce the number of for loops?

1 vue (au cours des 30 derniers jours)
pham
pham le 19 Nov 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?

Réponses (1)

Nicolas Schmit
Nicolas Schmit le 20 Nov 2017

Catégories

En savoir plus sur Loops and Conditional Statements 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