Any command in matlab equivilent to vech() in gauss

조회 수: 1 (최근 30일)
Lu zhang
Lu zhang 2016년 11월 21일
편집: dpb 2016년 11월 22일
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

답변 (1개)

dpb
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
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
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 CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by