Copy elements from one matrix to another under a condition

2 次查看(过去 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!

采纳的回答

Andrei Bobrov
Andrei Bobrov 2012-5-31

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Multidimensional Arrays 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by