Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding elements from 2 separate vector sources

Status
Not open for further replies.

myhouse

Programmer
Aug 15, 2002
4
US
Hello all,
I would like to know how to add the elements in vector vec1 to the elements in vec2. For instance: vec1(0) = [2,4,6] and vec2(0) = [1,3,5]. I need to extract the 2 and the 1 and add them together, then the 4 and the 3 and so on. Someone advised me to use a vector of vectors and that was cool but I'm still trying to figure that one out too. Thanks in advance for to anyone for any comments suggestions or code. I super appreciate it.
 
I would suggest looking at using parallel vectors, the value in the first vector cooresponds to a value in the second vector in the same spot. So you would just have to access one element technically (big hint!).
A Vector of Vectors wouldn't be very useful since you still have more processing to do, if you had a large amount of vectors then it could be useful for that process.
 
I was looking more along the lines of some code. I have tried many things that haven't worked. I need to know how to extract elements from a vector of vectors and then to add 2 elements from each vector together and to put the sums into a third vector in matrix form.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top