Reduce reduce the number of for loops?

1 次查看(过去 30 天)
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?

回答(1 个)

Nicolas Schmit
Nicolas Schmit 2017-11-20

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by