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
You can use this
idxs = find(triu(true(size(A)))');
which is an update on the answer of Matt. B, because you want row-wise representation.
This is comment to Keeran Brabazon answer. k = j + ni - i(i-1) /2 - this is equation from your post and it's wrong, the correct equation is k = j + (2*n -1 -i)*i/2. But we can't use it for finding i.
Equation from your post could be used to find i(row index), but we can't substitue i into your equation and get j, therefore formula for j in your post is wrong, so the final result will be looks like this:
i = floor( ( 2*n+1 - sqrt( (2n+1)*(2n+1) - 8*k ) ) / 2 ) ;(exactly like yours)
j = k - (2*n-1- i)*i/2; (different from your version, and i'm getting it by substituting i into my equation)