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

1. Member
Join Date
Jan 2010
Posts
44
Rep Power
0

## How 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!:)

2. By using a for loop and extracting each item, one at a time. If you experiment with it, you'll figure it out quickly.

3. I am a bit rusty... But I think this will do the trick:

Java Code:
```Vector<whatEver> v = new Vector<whatEver>;
whatEver matrix[][] = new whatEver[10][4];

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

4. Originally Posted by markw8500
I am a bit rusty... But I think this will do the trick:

Java Code:
```Vector<whatEver> v = new Vector<whatEver>;
whatEver matrix[][] = new whatEver[10][4];

for(int i=0; i<matrix.length; i++){
}```
Better to avoid magic numbers (i.e., the "3").

5. Good point my friend...

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

6. Member
Join Date
Jan 2010
Posts
44
Rep Power
0
Hi Guys, Thank you so much!
What does <whatEver> represent?

7. You have to specify what your vector is... AKA... String... Double... etc...

8. Senior Member
Join Date
Feb 2010
Location
Ljubljana, Slovenia
Posts
470
Rep Power
5
<whatEver> is the data type your matrix stores, for example, if your array stores ints, you would initialise you Vector as:
Java Code:
`Vector<Integer> v = new Vector<Integer>(); //not Vector<int>, vectors hold objects, not primitives`
This is known as a generic, initialising the vector in this manner assures, that it holds, and accepts only Integer objects.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•