如何用另一个矩阵中给定的权重替换邻接矩阵中 1 的值? 例如:
adjacent_matrix = [1 0 0 1; 0 0 1 1; 1 0 1 0; 0 1 1 0 ]
weight_matrix = [ 2 4 6 2; 4 5 1 3]
最终的矩阵应该是这样的:[2 0 0 4; 0 0 6 2; 4 0 5 0; 0 1 3 0]
最佳答案
代码-
out = adjacent_matrix';
out(out==1) = reshape(weight_matrix',1,numel(weight_matrix))';
out = out';
按照@chappjc 的建议,输入“adjacent_matrix”和“weight_matrix”保持不变。
关于algorithm - 我想用另一个较小矩阵中给出的权重替换邻接矩阵中 1 的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22312034/