For below given matrix,how it can be represented as undirected weighted graph G(V,E,W) where V is set of vertices,E is set of edges and W is set of weights.
4 2 3 1 4
2 2 3 1 4
2 3 3 1 4
1 2 3 1 4
4 2 3 1 5
Source code i tried:
%table2 is given matrix
bg = biograph(table2,[],'ShowArrows','off','ShowWeights','on');
h = view(bg);
Is this the right way to represent undirected weighted graph for my matrix?Iam getting 2 edges between same 2 verteces.Just like this
I got this output for your suggested code
Iam having 2 adjacency matrices.I have to perform below 2 operations:
1.I have to make 2 graphs from these 2 adjacency matrices.
2.Then i have to match vertices of 2 graphs depending on weights of edges in graph.
4 2 3 1 4
2 2 3 1 4
2 3 3 1 4
1 2 3 1 4
4 2 3 1 5
4 1 3 2 4
1 1 2 3 4
3 1 3 2 4
2 1 3 2 4
4 1 3 2 5
The way iam going is right or wrong?Please suggest me
To get only one edge between each vertex, you only want a triangular matrix.
If you try something like this:
table1 = (table2 + table2') - triu((table2 + table2'))
table1 =
0 0 0 0 0
4 0 0 0 0
5 6 0 0 0
2 3 4 0 0
8 6 7 5 0
bg = biograph(table1,[],'ShowArrows','off','ShowWeights','on');
h = view(bg);
Now I have assumed you want to sum up the weights from both edges. I.e. the weight of the edge between 1-2 equal the weight of the edge from 1->2 + 2->1, from your original matrix.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With