标签:io os for on cti ad as size br
%% 无向图邻接矩阵和关联矩阵转换
function w = incandadf(F,f)
%F为输入无向图矩阵可以是邻接矩阵或关联矩阵
%% 邻接矩阵转关联矩阵
if f == 0
m = sum(sum(F))/2;
n = size(F,1);
w = zeros(n,m);
k = 1;
for i = 1:n
for j =1 : n
if F(i,j) ~= 0
w(i,k) = 1;
w(j,k) = 1;
k = k + 1;
end
end
end
%% 关联矩阵 阵转邻接矩
else if f == 1
m = size(F,2);
n = size(F,1);
w = zeros(n,n);
for i = 1 : m
a = find(F(:,i) ~= 0);
w(a(1),a(2)) = 1;
w(a(2),a(1)) = 1;
end
else
printf(‘Please right f‘);
end
w
end
标签:io os for on cti ad as size br
原文地址:http://www.cnblogs.com/Kermit-Li/p/4158049.html