how to use the figure instead of biograph in graphshortestpath

3 views (last 30 days)
in graphshortestpath biograph is not work proprly please tell me how to use the figure instead of biograph
when i used graphshortestpath used biograph does not show error are encounter is like
Error using biograph (line 155)
CM must be a sparse or full square matrix
my code is
every_node_dist =
1.0000 2.0000 59.6129
1.0000 3.0000 60.2274
1.0000 4.0000 82.2382
1.0000 5.0000 40.5560
2.0000 3.0000 50.9495
2.0000 4.0000 30.4809
2.0000 5.0000 82.0061
3.0000 4.0000 46.1959
3.0000 5.0000 51.8620
4.0000 5.0000 92.7230
w=[every_node_dist(:,3)]'
w =
59.6129 60.2274 82.2382 40.5560 50.9495 30.4809 82.0061 46.1959 51.8620 92.7230
source_node_no=[every_node_dist(:,1)]'
source_node_no =
1 1 1 1 2 2 2 3 3 4
desti_node_no=[every_node_dist(:,2)]'
desti_node_no =
2 3 4 5 3 4 5 4 5 5
DG = sparse(source_node_no,destination_node_no,w)
DG =
(1,2) 59.6129
(1,3) 60.2274
(2,3) 50.9495
(1,4) 82.2382
(2,4) 30.4809
(3,4) 46.1959
(1,5) 40.5560
(2,5) 82.0061
(3,5) 51.8620
(4,5) 92.7230
h = view(biograph(DG,[],'ShowWeights','on'))
Error using biograph (line 155)
CM must be a sparse or full square matrix
please some one help me sort out problem

Answers (1)

Walter Roberson
Walter Roberson on 27 May 2015
maxnode = max([source_node_no, destination_node_no]);
DG = sparse(source_node_no, destination_node_no, w, maxnode, maxnode);
Your problem was that you were not creating a square sparse matrix.
  4 Comments
singh
singh on 27 May 2015
Walter thanks for response and please tell me one question plz
when i run DG then first column would be 0 and i delete this column from full sparse matrix.
now i am trying next to draw a biograph of these node.that time it take second column as a first column of DG.how to use or access second column as a second column after deletion from DG matrix not first column. thanks in advance
h = view(biograph(DG,[],'ShowWeights','on'))
Walter Roberson
Walter Roberson on 27 May 2015
How do you delete the column from the matrix? And why? Empty columns take only a few bytes of storage in sparse matrices, and most algorithms require that the adjacency matrix be square.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!