フィルターのクリア

Copy elements from one matrix to another under a condition

3 ビュー (過去 30 日間)
imperial1991
imperial1991 2012 年 5 月 31 日
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 Center および File ExchangeMultidimensional Arrays についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by