无向图的关联矩阵转化邻接矩阵matlab代码
时间: 2023-11-21 19:53:56 浏览: 103
无向图关联矩阵和邻接矩阵的相互转换算法代码-内含matlab源码和数据集.zip
```matlab
function W = convert(f, F)
% f为0时,将邻接矩阵F转化为关联矩阵W;f为1时,将关联矩阵F转化为邻接矩阵W
if f == 0
[m, n] = size(F);
W = zeros(m);
for i = 1:n
[x, y] = find(F(:, i));
for j = 1:length(x)
for k = j+1:length(x)
W(x(j), x(k)) = 1;
W(x(k), x(j)) = 1;
end
end
end
else
[m, n] = size(F);
W = zeros(m);
for i = 1:m
[x, y] = find(F(i, :));
for j = 1:length(x)
for k = j+1:length(x)
W(x(j), x(k)) = 1;
W(x(k), x(j)) = 1;
end
end
end
end
```
阅读全文