필터 지우기
필터 지우기

Ismember function -- return all indexes, not just lowest?

조회 수: 38 (최근 30일)
Tom
Tom 2013년 6월 12일
댓글: Captain Karnage 2023년 6월 27일
According to the Matlab documentation,
[Lia,Locb] = ismember(A,B) returns an array, Locb, containing the lowest index in B for each value in A that is a member of B.
Is there a way to return an array (or matrix) containing all indexes in B for each value in A that is a member of B?

채택된 답변

Matt J
Matt J 2013년 6월 12일
편집: Matt J 2013년 6월 12일
For numeric A and B, I would probably do something like this
Lia = ismember(A,B)
idx=find(Lia);
map=bsxfun(@eq, A(idx),B(:));
Then map(:,i) will be a logical index into B of all points where B equals A(idx(i))
  댓글 수: 1
Captain Karnage
Captain Karnage 2023년 6월 27일
The step idx=find(Lia) is not necessary, you can use A(Lia) to get the same result and it is a faster, more efficient way to index A in MATLAB.
Also, if B is not a vector, this will not work. You would need more steps to search a 2(or more)-D array.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Jan
Jan 2013년 6월 13일
Then the output can have different sizes for the different elements of A and a cell is required. What about a simple loop:
Out = cell(1, numel(A))
for iA = 1:numel(A)
Out{iA} = find(B == A(iA));
end

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by