Can I speed up an ismember operation?
Ältere Kommentare anzeigen
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 Kommentare
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
am 1 Feb. 2015
Bearbeitet: Christopher
am 1 Feb. 2015
per isakson
am 1 Feb. 2015
Bearbeitet: per isakson
am 1 Feb. 2015
"% 100 points in 10 random cells"   Is this comment misplaced?   grid_ind is a [100x1 double]
Christopher
am 1 Feb. 2015
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Programming finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!