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!