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 TugboatEng on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Finding positions of the entries of one vector in another

Status
Not open for further replies.

hoopz

Electrical
Joined
Sep 22, 2006
Messages
7
Location
US
I'm converting some code from R and I'm having trouble with a line of code that I feel like there should be a built in function for in Matlab. In R, the function is:

match(x,table)

which returns a vector of the positions of (first) matches of its first argument in its second.

So if I have two vectors:
V1 = {1,2,3,4,5,6}
V2 = {3,4,2,1,5,6}

then match(V1,V2) will return:

{4,3,1,2,5,6}


Anyone know a way I can do this same thing in Matlab without having to write my own function?

Thanks!
 
Have a look at the "intersect" function.

M

--
Dr Michael F Platten
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top