Copy elements from one matrix to another under a condition
1 view (last 30 days)
Show older comments
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 Comments
Accepted Answer
More Answers (0)
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!