下面的MATLAB程序 biograph 哪里出错了?
DG = sparse([1 1 1 1 1 1 1 2 2 2 2 2 2 3 3 3 3 3 4 4 4 4 5 5 5 6 6 7],[2 3 4 5 6 7 8 3 4 5 6 7 8 ...
4 5 6 7 8 5 6 7 8 6 7 8 7 8 8],W)
DG =
(1,2) 65
(1,3) 40
(2,3) 75
(1,4) 100
(2,4) 100
(3,4) 100
(1,5) 50
(2,5) 100
(3,5) 50
(4,5) 100
(1,6) 75
(2,6) 75
(3,6) 90
(4,6) 75
(5,6) 70
(1,7) 110
(2,7) 75
(3,7) 90
(4,7) 75
(5,7) 90
(6,7) 70
(1,8) 100
(2,8) 75
(3,8) 150
(4,8) 100
(5,8) 75
(6,8) 100
(7,8) 100
>> h = view(biograph(DG,[],'ShowWeights','on'))
Biograph object with 8 nodes and 28 edges.
Error using biograph (line 155)
CM must be a sparse or full square matrix
W = [.41 .99 .51 .32 .15 .45 .38 .32 .36 .29 .21];
DG = sparse([6 1 2 2 3 4 4 5 5 6 1],[2 6 3 5 4 1 6 3 4 3 5],W)
DG =。。。
h = view(biograph(DG,[],'ShowWeights','on'))
Biograph object with 6 nodes and 11 edges. 为什么这例题可以呢?我该创建怎样的连接矩阵? 展开
DG = sparse([1 1 1 1 1 1 1 2 2 2 2 2 2 3 3 3 3 3 4 4 4 4 5 5 5 6 6 7],[2 3 4 5 6 7 8 3 4 5 6 7 8 ...
4 5 6 7 8 5 6 7 8 6 7 8 7 8 8],W)这个稀疏矩阵用full函数还原后不是方阵square matrix
>>B = full(DG)
B =
0 65 40 100 50 75 110 100
0 0 75 100 100 75 75 75
0 0 0 100 50 90 90 150
0 0 0 0 100 75 75 100
0 0 0 0 0 70 90 75
0 0 0 0 0 0 70 100
0 0 0 0 0 0 0 100
是也7*8的矩阵,所以不是连接矩阵,用sparse函数时候要指明矩阵的行数和列数:
>> DG = sparse([1 1 1 1 1 1 1 2 2 2 2 2 2 3 3 3 3 3 4 4 4 4 5 5 5 6 6 7],[2 3 4 5 6 7 8 3 4 5 6 7 8 ...
4 5 6 7 8 5 6 7 8 6 7 8 7 8 8],W,8,8);
>> h = view(biograph(DG,[],'ShowWeights','on'))
Biograph object with 8 nodes and 28 edges.
搞定