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, 03: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, 03: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, 03: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, 03:50 AMFubarable
- 02-06-2010, 03: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, 06:43 AMtyang
Hi Guys, Thank you so much!

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

- 02-06-2010, 06: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`