Linearizing a 2D Array/Matrix

Alright, I need to write two methods, the first of which linearizes a matrix, such as 4x6. I need to convert it into 1 x (4*6). So the number of rows becomes one and the columns are the product of the dimensions of the matrix.

So a 3x3 would revert into a 1x9 where all the elements in each index were in their own column.

| 1 1 1 |

| 2 2 2 |

| 3 3 3 |

would need to convert to:

| 1 1 1 2 2 2 3 3 3 |

This is what I have so far for the linearize method.

Code:

`public Matrix linearize()`

{

Matrix result = new Matrix();

int rows = 1;

int columns = this.getColumns() * this.getRows();

result.theArray = new int[rows][columns];

for( int r = 0; r < result.getRows(); r++ )

for( int c = 0; c < result.getColumns(); c++ )

{

result.theArray[r][c] = theArray[c].length;

}

return result;

}

I have got the conversion to a 1xN matrix down, but i dont know how to fill the columns with the data which are in each index. I think this part needs to be changed, Code:

`result.theArray[r][c] = theArray[c].length;`

, but to what?

Thanks for any help.