Matlab spdiags function not do what I expect
B=[1 2 3;4 5 6;7 8 9;10 11 12]
d=[-3 0 2];
A=spdiags(B,d,4,7); %主对角线之下的对角线溢出时候,取最后一个值
B=spdiags(B,d,7,4); %主对角线之上的对角线溢出时候,取最后一个值
C=spdiags(B,d,4,4);
full(A)
full(B)
full(C)
Why would I get
ans =
2 0 3 0 0 0 0
0 5 0 6 0 0 0
0 0 8 0 9 0 0
10 0 0 11 0 12 0
ans =
2 0 9 0
0 5 0 12
0 0 8 0
1 0 0 11
0 4 0 0
0 0 7 0
0 0 0 10
ans =
0 0 8 0
0 5 0 0
0 0 0 0
2 0 0 0
Why is C so different from the previous two? In terms of having the numbers not shown on main diagnol and also having the numbers arranged from bottom to top?B=[1 2 3;4 5 6;7 8 9;10 11 12]
d=[-3 0 2];
A=spdiags(B,d,4,7); %主对角线之下的对角线溢出时候,取最后一个值
B=spdiags(B,d,7,4); %主对角线之上的对角线溢出时候,取最后一个值
C=spdiags(B,d,4,4);
full(A)
full(B)
full(C)
Why would I get
ans =
2 0 3 0 0 0 0
0 5 0 6 0 0 0
0 0 8 0 9 0 0
10 0 0 11 0 12 0
ans =
2 0 9 0
0 5 0 12
0 0 8 0
1 0 0 11
0 4 0 0
0 0 7 0
0 0 0 10
ans =
0 0 8 0
0 5 0 0
0 0 0 0
2 0 0 0
Why is C so different from the previous two? In terms of having the numbers not shown on main diagnol and also having the numbers arranged from bottom to top? B=[1 2 3;4 5 6;7 8 9;10 11 12]
d=[-3 0 2];
A=spdiags(B,d,4,7); %主对角线之下的对角线溢出时候,取最后一个值
B=spdiags(B,d,7,4); %主对角线之上的对角线溢出时候,取最后一个值
C=spdiags(B,d,4,4);
full(A)
full(B)
full(C)
Why would I get
ans =
2 0 3 0 0 0 0
0 5 0 6 0 0 0
0 0 8 0 9 0 0
10 0 0 11 0 12 0
ans =
2 0 9 0
0 5 0 12
0 0 8 0
1 0 0 11
0 4 0 0
0 0 7 0
0 0 0 10
ans =
0 0 8 0
0 5 0 0
0 0 0 0
2 0 0 0
Why is C so different from the previous two? In terms of having the numbers not shown on main diagnol and also having the numbers arranged from bottom to top? matlab MATLAB Answers — New Questions