Matrix union or extracting matrix elements

2 Ansichten (letzte 30 Tage)
Mehmet Candemir
Mehmet Candemir am 12 Mai 2011
Hi, I have very basic question I have two matrices. One is the adjacency matrix A and the other one W is filled random numbers(i.e. randi(10,10,10)). I want to extract all entries in the W for which A has non zero elements. if I do W(A) I got the numbers I need but in a column format and with out indexes. I just need to create a matrix where i keep weights of non zero edges.
[1 0 1] [4 7 9] [4 0 9]
[1 0 0] [8 5 4] = [8 0 0]
[0 0 1] [7 2 5] [0 0 5]

Akzeptierte Antwort

Andrei Bobrov
Andrei Bobrov am 12 Mai 2011
ons = [1 0 1;1 0 0;0 0 1] ;
a = [4 7 9;8 5 4;7 2 5];
W = a.*ons
  2 Kommentare
Mehmet Candemir
Mehmet Candemir am 12 Mai 2011
Why I have not thought about that!
Mehmet Candemir
Mehmet Candemir am 12 Mai 2011
Thanks

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by