Reduce reduce the number of for loops?
1 view (last 30 days)
Show older comments
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?
0 Comments
Answers (1)
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!