我想用邻接矩阵中的值1替换另一个较小矩阵中给出的权重

use*_*536 2 algorithm matlab adjacency-matrix

如何用邻接矩阵中的权重替换邻接矩阵中的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]
Run Code Online (Sandbox Code Playgroud)

最终矩阵应如下所示: [2 0 0 4; 0 0 6 2; 4 0 5 0; 0 1 3 0]

Div*_*kar 5

代码 -

out = adjacent_matrix';
out(out==1) = reshape(weight_matrix',1,numel(weight_matrix))';
out = out';
Run Code Online (Sandbox Code Playgroud)

输入'adjacent_matrix'和'weight_matrix'保持不变,如@chappjc所示.