Can I speed up an ismember operation?
Show older comments
I have a list of 100 random numbers 1-10:
numpoints = 100;
gridnum = 10;
grid_ind = randi(gridnum,[numpoints 1]); % 100 points in 10 random cells
and each of the 10 possible values has a corresponding list (of random length) of values, which are indexes to grid_ind:
for i=1:gridnum
neighbgrids{i} = randi(numpoints,[randi(5) 1]);
end
So far, so good. Now, I need to find the indexes for all elements in grid_ind which have the same values as in each cell list in neighbgrids. So I use:
for i=1:numpoints
neighblist{i} = find(ismember(grid_ind,neighbgrids{grid_ind(i)}));
end
But this turns out to be very slow. Is there a faster way to do this part?
5 Comments
The ismember operation looks very strange. The expression neighbgrids{grid_ind(i)}) will always take values in 1...numpoints, but grid_ind will always take values in the much smaller set 1...gridnum. In other words, you have lots of numbers in neighbgrids that grid_ind simply can never have membership in. Are you sure the code is correct?
Christopher
on 1 Feb 2015
Edited: Christopher
on 1 Feb 2015
per isakson
on 1 Feb 2015
Edited: per isakson
on 1 Feb 2015
"% 100 points in 10 random cells"   Is this comment misplaced?   grid_ind is a [100x1 double]
Christopher
on 1 Feb 2015
Accepted Answer
More Answers (0)
Categories
Find more on Programming in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!