How to link loops together?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Nicolas Pinell
le 9 Oct 2015
Commenté : Nicolas Pinell
le 12 Oct 2015
I am trying to make a program to get this numbers
0 1 0
0 0.8 0.2
0 0.6 0.4
0 0.4 0.6
0 0.2 0.8
0 0 1
0.1 0.9 0
0.1 0.7 0.2
0.1 0.5 0.4
0.1 0.3 0.6
0.1 0.1 0.8
0.1 0 0.9
and so on but I cant make the program to reduce the values of the second and third column when the first column increases.
This is my code.
Thanks
lai=0:0.1:1;
laj=1:-0.2:0;
lat=0:0.2:1;
for i=1,length(lai)
for j=1,i
for t=1,j
j
lam1(1,:)=lai;
lam2(1,:)=laj;
lam3(1,:)=lat;
end
end
end
0 commentaires
Réponse acceptée
Walter Roberson
le 10 Oct 2015
The syntax for "for" loops is
for j=1:i
not
for j=1,i
The line you entered does have meaning: in particular it is the same as
for j = [1]
i
which is to say that it would set j to 1 and then print out the value of i, and then after the rest of the statements in the body executed once the loop would be finished
Plus de réponses (0)
Voir également
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!