Question about ismember replacements

조회 수: 1 (최근 30일)
Brian
Brian 2012년 12월 7일
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에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by