• 大小: 2KB
    文件类型: .m
    金币: 1
    下载: 0 次
    发布日期: 2021-05-06
  • 语言: Matlab
  • 标签: MATLAB  

资源简介

根据网络邻接矩阵画出有向图或无向图 可用于交通、电能等网络的可视化

资源截图

代码片段和文件信息

function tu_plot(relcontrol)
%由邻接矩阵画图?
%输入为邻接矩阵,必须为方阵;?
%第二个输入为控制量,0表示无向图,1表示有向图。默认值为0

r_size=size(rel);
if nargin<2
    control=0;
end

if r_size(1)~=r_size(2)
    disp(‘Wrong?Input!?The?input?must?be?a?square?matrix!‘);
    return;
end
len=r_size(1);

rho=10;    %限制图尺寸的大小
r=2/1.05^len;    %点的半径?
theta=0:(2*pi/len):2*pi*(1-1/len);
[pointxpointy]=pol2cart(theta‘rho);
theta=0:pi/36:2*pi;
[tempxtempy]=pol2cart(theta‘r);
point=[pointxpointy];
hold on

for i=1:len
    temp=[tempxtempy]+[point(i1)*ones(length(tempx)1)point(i2)*ones(length(tempx)1)];
    plot(temp(:1)temp(:2)‘r‘);
    text(point(i1)-0.3point(i2)num2str(i));
end

for i=1:len
    for j=1:len
        if rel(ij)
            link_plot(point(i:)point(j:)rcontrol);    %连接有关系的点
        end
    end
end
set(gca‘XLim‘[-rho-rrho+r]‘YLim‘[-rho-rrho+r]);
axis off
end
%%
function link_plot(point1point2rco

评论

共有 条评论