For loop count question
이전 댓글 표시
I have a count question regarding for loop.
May I ask how to get the "count" number representing from 1 to 86625?
Or there is a better to code? Thank you!
a1=-70:5:100;
a2=-60:5:60;
a3=-50:10:50;
a4=-40:10:40;
U1=1*ones(100,1);
U2=2*ones(100,1);
U3=3*ones(100,1);
U4=4*ones(100,1);
x=0.5*ones(100,1);
y=zeros(100,1);
z=2*ones(100,1);
diff=zeros(length(a1)*length(a2)*length(a3)*length(a4),5);
% length(a1)*length(a2)*length(a3)*length(a4)=35*25*11*9=86625
for i=1:length(a1)
for ii=1:length(a2)
for iii=1:length(a3)
for iiii=1:length(a4)
y=x+a1(i)*U1+a2(ii)*U2+a3(iii)*U3+a4(iiii)*U4;
count=? % This goes from 1 to 86625 represented by i, ii, iii and iii
diff(count,1)=sqrt(sum((z-y).^2)/length(U1));
diff(count,2)=a1(i);
diff(count,3)=a2(ii);
diff(count,4)=a3(iii);
diff(count,5)=a4(iiii);
end
end
end
end
채택된 답변
추가 답변 (1개)
Rik
2019년 4월 18일
0 개 추천
Initialize count to 0 before your nested loop and do count=count+1; inside the inner loop.
카테고리
도움말 센터 및 File Exchange에서 MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!