How can I extract the last column of a given matrix?

For example,

matrix[][] = new [10][4];

How can I get the last column of a matrix as a vector?

Thank you very much!:)

Printable View

- 02-06-2010, 02:25 AMtyangHow can I extract the last column of a given matrix?
How can I extract the last column of a given matrix?

For example,

matrix[][] = new [10][4];

How can I get the last column of a matrix as a vector?

Thank you very much!:) - 02-06-2010, 02:47 AMFubarable
By using a for loop and extracting each item, one at a time. If you experiment with it, you'll figure it out quickly.

- 02-06-2010, 02:48 AMmarkw8500
I am a bit rusty... But I think this will do the trick:

Code:`Vector<whatEver> v = new Vector<whatEver>;`

whatEver matrix[][] = new whatEver[10][4];

for(int i=0; i<matrix.length; i++){

v.addElement(matrix[i][3]);

}

- 02-06-2010, 02:50 AMFubarable
- 02-06-2010, 02:55 AMmarkw8500
Good point my friend...

Quote:

for(int i=0; i<matrix.length; i++){

v.addElement(matrix[i][matrix[0].length-1]);

}

- 02-06-2010, 05:43 AMtyang
Hi Guys, Thank you so much!

What does <whatEver> represent? - 02-06-2010, 05:47 AMmarkw8500
You have to specify what your vector is... AKA... String... Double... etc...

- 02-06-2010, 05:48 AMm00nchile
<whatEver> is the data type your matrix stores, for example, if your array stores ints, you would initialise you Vector as:

Code:`Vector<Integer> v = new Vector<Integer>(); //not Vector<int>, vectors hold objects, not primitives`