- #1
Mindscrape
- 1,861
- 1
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).
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.
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.