Creating matrix with loops
조회 수: 1 (최근 30일)
이전 댓글 표시
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!
댓글 수: 0
답변 (1개)
Laurent
2013년 10월 7일
편집: Laurent
2013년 10월 7일
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];
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!