Copy elements from one matrix to another under a condition
1 次查看(过去 30 天)
显示 更早的评论
Hi guys I was wondering if there's an efficient way of doing this.
Say I have matrix A = [1 0; 1 0] and matrix B = [0.5 0.4; 0.4 0.3]
I want to transform the entries of A which are 1 to their corresponding entries in B. For instance, my desired result is A' = [0.5 0; 0.4 0]. I know I can use a for loop but in the case in which A has a large dimension this would be very consuming. any shortcuts you know of?
I was thinking of this command A(A==1) = ? or some sort.
(In my application, A would be the adjacency matrix of a graph, B would be the edge weights. Although the A matrix I gave is atypical since the node 1 has a loop connecting to itself)
Thanks!
0 个评论
采纳的回答
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!