matlab 画network,papa的儿子

本文介绍了一种使用MATLAB绘制带权重的随机图形的方法。通过定义节点数量和连接方式,利用polar坐标转换为Cartesian坐标,并随机生成节点间的连接与权重。最终实现了图形的可视化展示,包括节点、连接线及权重的颜色变化。



clear all
clc
clf


%% 
n=18;
theta = linspace(0,2*pi,(n+1));
theta = theta(1:end-1);
[x,y] = pol2cart(theta,1);

links=triu(round(rand(length(theta))));%# this is a random list of connections
[ind1,ind2] = ind2sub(size(links),find(links(:)));

txt = cellstr(num2str((1:n)','%02d'));

% p_tm=symrcm(links);
% links_new=links(p_tm,p_tm);
% txt = txt(p_tm);

weig =rand(size(ind1));

col_mm = jet(length(ind1));

plot(x,y,'.k','markersize',20);
hold on
axis equal

arrayfun(@(p,q,r,colr,colg,colb)line([x(p),x(q)],[y(p),y(q)],...
    'linewidth',1+2*r,'color',[colr colg colb]),ind1,ind2,weig...
                                    ,col_mm(:,1),col_mm(:,2),col_mm(:,3));
axis equal off

h = text(x.*1.1, y.*1.1, txt, 'FontSize',14);

for i=1:n
set(h(i), 'Rotation',theta(i)*180/pi-90);
end

colorbar



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值