Creating matrix with loops

4 vues (au cours des 30 derniers jours)
Simon
Simon le 7 Oct 2013
Modifié(e) : Laurent le 7 Oct 2013
Hello
I wanna creat a code for a loop for a matrix which creat nodal points (for 4 legs in 3d-koordinate system) in a matrix. I can make it creat the nodal point for 1 leg with this code:
le=1;
d=5;
for no=1:d
x1=no*le;
x2=(no-1)*le;
x3=0
nodal(no,:) = [x1 x2 x3 % [nodal nr. x-koord. y-koord]
] ;
end
disp(nodal);
but what i want it to restart after 5 point and make a matrix like this.
1 0 0 0
2 0 0 2
3 0 0 4
4 0 0 6
5 0 0 8
6 1 0 0
7 1 0 2
8 1 0 4
9 1 0 6
10 1 0 8
11 0 1 0
12 0 1 2
13 0 1 4
14 0 1 6
15 0 1 8
16 1 1 0
17 1 1 2
18 1 1 4
19 1 1 6
20 1 1 8
I have tryed to make more loops, but nothing it working. I hope somebody can help - thanks!

Réponses (1)

Laurent
Laurent le 7 Oct 2013
Modifié(e) : Laurent le 7 Oct 2013
You don't need loops to get the matrix you want, you can make the individual columns by playing a bit around with divisions and rounding and then merge them all together.
y1=cumsum(ones(20,1));
y2=rem(floor((y1-1)/5),2);
y3=rem(floor((y1-1)/10),2);
y4=rem((y1-1)*2,10);
y=[y1 y2 y3 y4];

Catégories

En savoir plus sur Multidimensional Arrays 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!

Translated by