Continue to Site

# How work this sparse matrix in matlab?

Status
Not open for further replies.

#### jalal.baba

##### Junior Member level 1
Hi
i can't understand how work this code in matlab?
Code:
A = sparse([f(:,1); f(:,1); f(:,2); f(:,2); f(:,3); f(:,3)], ...
[f(:,2); f(:,3); f(:,1); f(:,3); f(:,1); f(:,2)], ...
1.0);

I have f matrix:
f =

3 4 1
4 3 2
4 5 1
5 4 2
5 6 1
6 5 2
6 7 1
7 6 2
7 8 1
8 7 2
8 9 1
9 8 2
9 10 1
10 9 2
10 11 1
11 10 2
11 12 1
12 11 2
12 13 1
13 12 2
13 14 1
14 13 2
14 15 1
15 14 2
15 16 1
16 15 2
16 17 1
17 16 2
17 18 1
18 17 2
18 19 1
19 18 2
19 20 1
20 19 2
20 21 1
21 20 2
21 22 1
22 21 2
22 3 1
3 22 2

out put is:
A =

(3,1) 2
(4,1) 2
(5,1) 2
(6,1) 2
(7,1) 2
(8,1) 2
(9,1) 2
(10,1) 2
(11,1) 2
(12,1) 2
(13,1) 2
(14,1) 2
(15,1) 2
(16,1) 2
(17,1) 2
(18,1) 2
(19,1) 2
(20,1) 2
(21,1) 2
(22,1) 2
(3,2) 2
(4,2) 2
(5,2) 2
(6,2) 2
(7,2) 2
(8,2) 2
(9,2) 2
(10,2) 2
(11,2) 2
(12,2) 2
(13,2) 2
(14,2) 2
(15,2) 2
(16,2) 2
(17,2) 2
(18,2) 2
(19,2) 2
(20,2) 2
(21,2) 2
(22,2) 2
(1,3) 2
(2,3) 2
(4,3) 2
(22,3) 2
(1,4) 2
(2,4) 2
(3,4) 2
(5,4) 2
(1,5) 2
(2,5) 2
(4,5) 2
(6,5) 2
(1,6) 2
(2,6) 2
(5,6) 2
(7,6) 2
(1,7) 2
(2,7) 2
(6,7) 2
(8,7) 2
(1,8) 2
(2,8) 2
(7,8) 2
(9,8) 2
(1,9) 2
(2,9) 2
(8,9) 2
(10,9) 2
(1,10) 2
(2,10) 2
(9,10) 2
(11,10) 2
(1,11) 2
(2,11) 2
(10,11) 2
(12,11) 2
(1,12) 2
(2,12) 2
(11,12) 2
(13,12) 2
(1,13) 2
(2,13) 2
(12,13) 2
(14,13) 2
(1,14) 2
(2,14) 2
(13,14) 2
(15,14) 2
(1,15) 2
(2,15) 2
(14,15) 2
(16,15) 2
(1,16) 2
(2,16) 2
(15,16) 2
(17,16) 2
(1,17) 2
(2,17) 2
(16,17) 2
(18,17) 2
(1,18) 2
(2,18) 2
(17,18) 2
(19,18) 2
(1,19) 2
(2,19) 2
(18,19) 2
(20,19) 2
(1,20) 2
(2,20) 2
(19,20) 2
(21,20) 2
(1,21) 2
(2,21) 2
(20,21) 2
(22,21) 2
(1,22) 2
(2,22) 2
(3,22) 2
(21,22) 2

Status
Not open for further replies.