How to rotate row elements in a 3 x 3 matrix

Nsin991
Nsin991 used Ask the Experts™
on
I am trying to reverse the row elements in a 3 x 3 matrix.  My matrix currently looks like this:

int i;
for (k = 0; k < RWIDTH ;k++)
   for (j = 0; j < RHEIGHT; j++)
   {
        data2 [j][k][0] = data[k][j][0];
        data2 [j][k][1] = data[k][j][1];
        data2 [j][k][2] = data[k][j][2];
   }

How do I reverse the row elements?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
ozo
Most Valuable Expert 2014
Top Expert 2015

Commented:
I'm not sure what you are asking.
Do you want
        data2 [j][k][0] = data[k][j][2];
        data2 [j][k][1] = data[k][j][1];
        data2 [j][k][2] = data[k][j][0];
?

Author

Commented:
No, let me clarify.

for (k = 0; k < RWIDTH ;k++)
   for (j = 0; j < RHEIGHT; j++)
   {
        data2 [j][k][0] = data[k][j][0]
        data2 [j][k][1] = data[k][j][1];
        data2 [j][k][2] = data[k][j][2];
   }

I am trying to flip the value of the rows and columns from the data array for data2 array.  Also, i want the reverse of the elements in the row. if data [2,3], then data2 [-3,2]
Most Valuable Expert 2014
Top Expert 2015
Commented:
I'm still confused
Do you mean
        data2 [j][k][0] = data[RWIDTH-1-k][j][0]
?
Nsin991

So, to make it clear what you want, if your matrix is this:

    Before
    1     2     3
    4     5     6
    7     8     9

then please fill in how you want it to look afterwards:

    After
    ?     ?     ?
    ?     ?     ?
    ?     ?     ?

Author

Commented:
I apologize for still being confusing.  But, yes that is what I meant.  In my case, it is actually the opposite:

        data2 [RWIDTH-1-j][k][0] = data[k][j][0]

But, this is what I was referring to.  Thank you.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial