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
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!:)
By using a for loop and extracting each item, one at a time. If you experiment with it, you'll figure it out quickly.
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]);
}
Good point my friend...
Quote:
for(int i=0; i<matrix.length; i++){
v.addElement(matrix[i][matrix[0].length-1]);
}
Hi Guys, Thank you so much!
What does <whatEver> represent?
You have to specify what your vector is... AKA... String... Double... etc...
<whatEver> is the data type your matrix stores, for example, if your array stores ints, you would initialise you Vector as:
This is known as a generic, initialising the vector in this manner assures, that it holds, and accepts only Integer objects.Code:Vector<Integer> v = new Vector<Integer>(); //not Vector<int>, vectors hold objects, not primitives