Any command in matlab equivilent to vech() in gauss
2 ビュー (過去 30 日間)
古いコメントを表示
The definition of vech() in Gauss is
vech
Purpose Vectorizes a symmetric matrix by retaining only the lower triangular portion of the matrix.
Format v = vech(x);
Input
Output
Remarks As you can see from the example below, vech will not check to see if x is symmetric. It just packs the lower triangular portion of the matrix into a column vector in row-wise order.
Example x = seqa(10,10,3) + seqa(1,1,3)’;
v = vech(x);
sx = xpnd(v);
x NxN symmetric matrix.
v (N*(N+1)/2)x1 vector, the lower triangular portion of the matrix
x
11 12 13
21 22 23
31 32 33
=
v
11
21
22
31
32
33
Something like
mask = tril(true(size(a)),0);
out = a(mask);
can only return like
11
21
31
22
32
33
0 件のコメント
回答 (1 件)
dpb
2016 年 11 月 21 日
It's simply row-major vis a vis column-major Matlab storage order --
>> triu(x')
ans =
11 21 31
0 22 32
0 0 33
>> ans(ans>0)
ans =
11
21
22
31
32
33
>>
2 件のコメント
Guillaume
2016 年 11 月 21 日
or as a one liner:
nonzeros(triu(x'))
Both assume that there are no 0 in the original matrix. So, this may be safer:
transx= x'
transx(triu(true(size(transx))))
dpb
2016 年 11 月 21 日
編集済み: dpb
2016 年 11 月 22 日
"assume that there are no 0 in the original matrix"
Trudat; was only showing OP really the only difference is internal storage order.
With your refinement on selection of values to keep, it probably would be clearer to write
tril(x).'
as the selection which at least does use tril instead of triu the latter of which is undoubtedly disconcerting.. :)
It would take some playing, however, to get the testing to match for the original array vis a vis the transposed triangular one; not sure a one-liner is then possible altho I didn't work on it too long...
参考
カテゴリ
Help Center および File Exchange で Resizing and Reshaping Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!