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.