# How to rotate row elements in a 3 x 3 matrix

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® is a registered trademark of EXPERTS EXCHANGE®
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];
?

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]
?

Commented:
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
?     ?     ?
?     ?     ?
?     ?     ?

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