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?

답변 (1개)

Youssef  Khmou
Youssef Khmou 2013년 9월 1일
편집: Youssef Khmou 2013년 9월 1일

0 개 추천

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

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.
Youssef  Khmou
Youssef Khmou 2013년 9월 2일
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)=[]
Nac selli
Nac selli 2017년 5월 12일
Hello, i need some help to calculate the edge weight. can i get the code that you are using. thank you

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Just for fun에 대해 자세히 알아보기

제품

질문:

2013년 8월 31일

댓글:

2017년 5월 12일

Community Treasure Hunt

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

Start Hunting!

Translated by