I want to add together the cross-diagonal elements in a matrix. For example, I have a 3*3 Matrix which is two dimensional, I want to convert it to one dimensional:
-------------------
| 1 | 2 | 3 |
-------------------
A= | 4 | 5 | 6 |
-------------------
| 7 | 8 | 9 |
-------------------
final output will be,
____ ____ ____ ____ ____
B= |1 | 6 | 15 | 14 | 9 |
|____|____|____|____|____|
First cross-diagonal A[0][0] will be copied to B[0].
Then the next cross-diagonal elements A[1][0] and A[0][1] will be added and copied to B[1], i.e. 4 and 2 will be added.
Then the next cross-diagonal elements A[2][0] and A[1][1] and A[0][2] will be added and copied to B[2], i.e. 7, 5 and 3 will be added.
And so on…
Notice that for each diagonal, the sum of row-index and column-index is equal to the index of B array. Based on this fact, you can make a algorithm like this: