Question: Convert matrix indexes

Hello!

I have a matrix and all elements has two indexes. For example 3x3 case:

1,1 1,2 1,3

2,1 2,2 2,3

3,1 3,2 3,3

So if I want to travers this matrix in zig-zag way and fill it with increasing numbers I will get this matrix:

1 2 6

3 5 7

4 8 9

From 1 to 2,3 and 4,5,6 ...

We have 9 elemets in this order:

1 - (1,1); 2 - (1,2); 3 - (2,1); 4 - (3,1); 5 - (2,2); 6 - (1,3); 7 - (2,3); 8 - (3,2); 9 - (3,3).

The question is - do we have a way to convert two indexes in one digit like (3,1) -> 4 or (2,3) -> 7

Thank you!

Could you help me please if there is a way to convert to

Please Wait...