Question about ismember replacements

1 次查看(过去 30 天)
Hello, thanks for reading this,
I have a question about a very timely procedure in a MATLAB script I have. Something I have to do repeatedly is check for point indices in a global matrix, and my repetitive calls are getting to be very costly time-wise.
A rough snippet of the code I have is:
l2 = ismember(randomgen_ptmx,bifPt, 'rows');
[maxval,ind] = max(l2);
counter = 1;
for i=1:length(randomgen_connMx)
if ind == randomgen_connMx(i,1)
dag(counter) = i;
counter = counter+1;
end
end
where bifPt is a 1x3 array, and randomgen_ptmx is a nx3 matrix. What I do in the first three lines is search for the index of the big point as it exists in the randomgen_ptmx matrix, then I take that index and dearch for where it is the first entry in a n1x2 matrix (randomgen_connMx).
So, a simple explanation is I want to see where the index of bifPt in the global matrix randomgen_ptmx is in the first column entry of randomgen_connMx. I check for this in a ismember function, but when I profiled my code my repetitive calls to ismember is by far the biggest time waste I have. Are there better ways to do this?
Thanks a lot for your advice!

采纳的回答

Brian
Brian 2012-12-7
Actually, I managed to solve this myself:
bif_index = find(bifPt(1)==randomgen_ptmx(:,1) & ... bifPt(2)==randomgen_ptmx(:,2),1,'last');
dag = find(bif_index == randomgen_connMx(:,1));
did everything I needed to do. Hope this helps anyone else with a ismember problem.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by