資源簡介
根據網絡鄰接矩陣畫出有向圖或無向圖
可用于交通、電能等網絡的可視化
代碼片段和文件信息
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
- 上一篇:基于TDOA定位的仿真程序
- 下一篇:支持向量機刀具磨損預測模型及MATLAB仿真
評論
共有 條評論