首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Matlab+图theory+权重分配

Matlab+图theory+权重分配
EN

Stack Overflow用户
提问于 2012-10-26 14:21:51
回答 1查看 486关注 0票数 0

我一直在尝试标记一个无向图的边,而且,我正在使用这个matgraph工具!我成功地制作了一个图,我只想给它分配权重……请帮帮我!!

这是我尝试过的,

代码语言:javascript
复制
clear all;
close all;
clc;
g=graph;
for k=1:6

add(g,k,k+1)
add(g,1,4)
add(g,5,7)
end
ndraw(g);
x=rand(1,1);
y=rand(1,1)
A =[0 x 0 x 0 0 0;
x 0 x 0 0 0 0;
0 x 0 x 0 0 0;
x 0 x 0 x 0 0;
0 0 0 y 0 x x;
0 0 0 0 x 0 x;
0 0 0 0 x x 0]

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-10-26 15:10:41

如果我没理解错的话,你可以在你写的代码后面加上这段代码:

代码语言:javascript
复制
% get line info from the figure
lineH = findobj(gca, 'type', 'line');
xData = cell2mat(get(lineH, 'xdata')); % get x-data
yData = cell2mat(get(lineH, 'ydata')); % get y-data

% if an edge is between (x1,y1)<->(x2,y2), place a label at
% the center of the line, i.e. (x1+x2)/2 (y1+y2)/2 etc
labelposx=mean(xData');
labelposy=mean(yData');

% generate some random weights vector
weights=randi(21,length(labelposx),1); 

% plot the weights on top of the figure
text(labelposx,labelposy,mat2cell(weights), 'HorizontalAlignment','center',... 
                                            'BackgroundColor',[.7 .9 .7]); 

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13081797

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档