MATLAB Match row vector in matlab efficiently

  • Thread starter Mindscrape
  • Start date
1,860
0
I would like to take a row vector of my choosing and see if it matches any other rows in say a 1e6 x 100 array. I want to do this as fast as possible with matlab. There should only be, if any, one match with the actual data I'll be using because every row in my data (the matrix) will be unique.

What I've come up so far is to simulate the unique rows with rand, and the fastest method seems to using bsxfun (I'm getting ~.3 seconds on my machine).

Code:
A=ceil(10*rand(1e6,100));
B=ceil(10*rand(1,100));
tic
index=find(all(bsxfun(@eq,A,B),2));
toc
index
this is faster than both using ismember and using a for loop to check each row one-by-one. Still, there is something that is bugging me, something that is telling me that there should be an even more elegant and quicker way to find if there is a match and where that match is.
 

Want to reply to this thread?

"Match row vector in matlab efficiently" You must log in or register to reply here.

Physics Forums Values

We Value Quality
• Topics based on mainstream science
• Proper English grammar and spelling
We Value Civility
• Positive and compassionate attitudes
• Patience while debating
We Value Productivity
• Disciplined to remain on-topic
• Recognition of own weaknesses
• Solo and co-op problem solving
Top