How to draw a weighted graph G=(V,E)

Assume that we have a weighted graph G=(V,E). We know its adjacency matrix and position of vertices. After some calculations we see some edges has weights w=0. then we have to delete some edges from the original graph and redraw the graph. my question is that how I can do this?

Answers (1)

Youssef  Khmou
Youssef Khmou on 1 Sep 2013
Edited: Youssef Khmou on 1 Sep 2013
is the original graph a sparse matrix? generally you can delete the values using this example :
% given a vector( or matrix) G
G=randn(10,2);
% some zeros values
G(2:5,1)=0;
% REmoving zeros
G(G==0)=[]; % this operation maps the matrix to vector
Next you can reshape the result for different dimensions .

3 Comments

Thanks for the comment.
Somehow, it is not. because I am using the random creation graph, then it depends on MATLAB. But most of the time is not. Here is my code:
this are inputs
n = 30;
dist = 0.3;
[A, points] = graph2d(n,dist);
After calculation edge weights I have following
w =
0.0000
0.0068
0.0000
0.0000
0.0116
0.0231
0.0237
0.0063
0.0117
0.0106
0.0117
0.0025
0.0117
0.0117
0.0023
0.0035
0.0046
0.0057
0.0039
0.0035
0.0093
0.0174
0.0072
0.0107
0.0128
0.0000
0.0141
0.0168
0.0000
0.0168
0.0025
0.0128
0.0128
0.0128
0.0045
0.0014
0.0139
0.0188
0.0000
0.0188
0.0188
0.0297
0.0237
0.0126
0.0149
0.0126
0.0063
0.0149
0.0138
0.0141
0.0141
0.0027
0.0016
0.0139
0.0139
0.0068
0.0160
0.0158
0.0140
0.0156
0.0104
0.0143
0.0228
0.0188
0.0188
0.0168
0.0000
0.0000
0.0255
0.0000
0.0127
0.0000
0.0126
0.0000
0.0296
0.0149
0.0127
0.0126
0.0188
0.0143
0.0116
0.0063
0.0231
0.0000
0.0243
0.0149
0.0141
0.0019
0.0139
Now in the original graph I have to delete some edges and the draw graph again, because there are some edges weights with w=0. By instruction that you mentioned I think it is not possible do anything for this model.
I think it is possible to resolve the problem if you provide all the details about your program, because i do not have the graph2d function,
Waiting for details i think you can remove the zeros with w(w==0)=[]
Hello, i need some help to calculate the edge weight. can i get the code that you are using. thank you

Sign in to comment.

Categories

Find more on Creating, Deleting, and Querying Graphics Objects in Help Center and File Exchange

Products

Asked:

on 31 Aug 2013

Commented:

on 12 May 2017

Community Treasure Hunt

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

Start Hunting!