vectorization of symmetrical matrix with off-diagonal vectors multiplied with 2

5 ビュー (過去 30 日間)
Tim Elbers
Tim Elbers 2019 年 5 月 14 日
編集済み: Tim Elbers 2019 年 5 月 20 日
Hi all,
I want to vectorize a matrix H. However the matrix H is symetric in the off-diagonal entries. The off diagonal entries on the to disired vector have the value of 2*H(ij).
imagine H as:
H =
1 6 7 8 9
6 2 10 11 12
7 10 3 13 14
8 11 13 4 15
9 12 14 15 5
than, the to desired vector has the following form. if H is nxn matrix. the vector should have dimensions n(n+1)/2 with the off-diagonal vectors 2*H(ij) like
1 2*6 2*7 2*8 2*9 2*10 2*11 2*12 3 2*13 2*14 4 2*15 5
What is the best way to solve this problem?

採用された回答

Andrei Bobrov
Andrei Bobrov 2019 年 5 月 14 日
編集済み: Andrei Bobrov 2019 年 5 月 14 日
k = 2;
o = ones(size(H));
Hl = H.*(tril(o,-1)*(k-1) + 1);
out = Hl(tril(o)>0);
or
e = H.*((k-1)*(1-eye(size(H))) + 1);
out = e(tril(e) > 0);

その他の回答 (1 件)

Tim Elbers
Tim Elbers 2019 年 5 月 20 日
編集済み: Tim Elbers 2019 年 5 月 20 日
Thank you,
i have an aditional question,
which is like the same problem but than reversed.
if i have obtained the vector .
1 2*6 2*7 2*8 2*9 2*10 2*11 2*12 3 2*13 2*14 4 2*15 5
how could i obtain the same symatrical matrix of underneath form if only this vector is given.
H =
1 6 7 8 9
6 2 10 11 12
7 10 3 13 14
8 11 13 4 15
9 12 14 15 5
Thanks in advance

カテゴリ

Help Center および File ExchangePhysics についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by