How to link loops together?

1 vue (au cours des 30 derniers jours)
Nicolas Pinell
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

Réponse acceptée

Walter Roberson
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
  1 commentaire
Nicolas Pinell
Nicolas Pinell le 12 Oct 2015
Thanks I solved that problem but I don't know how to save the values of i into another variable. Or how to save the printed values. Can you help me with that too?

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by