lundi 2 février 2015

Need to reset a counter variable in Matlab

Ok so I need to make an array using a for loop that is the following



[13 14 15]
[10 11 12]
[7 8 9]
[4 5 6]
[1 2 3]


here's what I have so far. It works but the function could be alot prettier



clc
clear all
m=1;
i=0;
for m=1:15
i=i+1;
if m<=3
matrix(5,i)=m;
end
if m>3 && m<=6
matrix(4,i-3)=m;
end
if m>6 && m<=9
matrix(3,i-6)=m;
end
if m>9 && m<=12
matrix(2,i-9)=m;
end
if m>12 && m<=15
matrix(1,i-12)=m;
end
end


I want to get rid of the i-12 etc. by maybe using another for loop that infinitely counts from 1 to three and terminates through a different parameter?


Been fiddling with this one for a while. Any help would be appreciated!


Aucun commentaire:

Enregistrer un commentaire