Linear indexing in symmetric matrices

前端 未结 8 1238
遇见更好的自我
遇见更好的自我 2021-01-05 04:09

We can access matrices using linear indexing, which follows this pattern

0 1 2

3 4 5

6 7 8

It\'s easy to get the i,j coordinates for this cas

8条回答
  •  青春惊慌失措
    2021-01-05 04:19

    Since nobody has posted a Matlab solution yet, here's a simple one-liner:

    idxs = find(triu(true(size(A))))
    

    Given matrix A, this will return a vector of all your indices, such that idxs(k) returns the k-th linear index into the upper triangular portion of the matrix.

提交回复
热议问题