Matlab sparse matrix does not come out as I would expect
This is my code:
S=sparse([1 3 2 1 4],[3 1 4 1 4],[1 2 3 4 5],4,4)
full(s)
However, when I run it, I get:
‘S =
(1,1) 4
(3,1) 2
(1,3) 1
(2,4) 3
(4,4) 5
ans=
0 0 0 1
0 1 0 0
1 2 0 0
0 0 3 0′
Please tell me why ans is not [4 0 1 0;0 0 0 3; 2 0 0 0; 0 0 0 5]?This is my code:
S=sparse([1 3 2 1 4],[3 1 4 1 4],[1 2 3 4 5],4,4)
full(s)
However, when I run it, I get:
‘S =
(1,1) 4
(3,1) 2
(1,3) 1
(2,4) 3
(4,4) 5
ans=
0 0 0 1
0 1 0 0
1 2 0 0
0 0 3 0′
Please tell me why ans is not [4 0 1 0;0 0 0 3; 2 0 0 0; 0 0 0 5]? This is my code:
S=sparse([1 3 2 1 4],[3 1 4 1 4],[1 2 3 4 5],4,4)
full(s)
However, when I run it, I get:
‘S =
(1,1) 4
(3,1) 2
(1,3) 1
(2,4) 3
(4,4) 5
ans=
0 0 0 1
0 1 0 0
1 2 0 0
0 0 3 0′
Please tell me why ans is not [4 0 1 0;0 0 0 3; 2 0 0 0; 0 0 0 5]? matlab MATLAB Answers — New Questions