%% 无向图邻接矩阵和关联矩阵转换
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);
if F(a(1),i) == 1
w(a(1),a(2)) = 1;
else
w(a(2),a(1)) = 1;
end
end
else
printf('Please right f');
end
w
end