For loop count question
Afficher commentaires plus anciens
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
Réponse acceptée
Plus de réponses (1)
Rik
le 18 Avr 2019
0 votes
Initialize count to 0 before your nested loop and do count=count+1; inside the inner loop.
1 commentaire
Tsuwei Tan
le 18 Avr 2019
Catégories
En savoir plus sur MATLAB dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!