필터 지우기
필터 지우기

How to find mutual arrays position of multiple matrices with different length

조회 수: 2 (최근 30일)
I have two matrices and I want the corresponding all indices, not just the first one. Here is the example
A = ...
[2 2 4
4 5 4
1 1 4
4 3 2
1 2 4
2 4 4
1 4 1
1 1 1
5 3 3
4 3 5
4 5 4]
and
B = [ 1 4 1
4 3 5
4 5 4]
I used intersect as follows and got the following output:
[AB,ia,ib] = intersect(A,B,'rows')
AB =
1 4 1
4 3 5
4 5 4
ia =
7
10
2
ib =
1
2
3
is it possible to get ia = [7 10 2, 11]?

채택된 답변

Walter Roberson
Walter Roberson 2018년 10월 27일
[~, rowidx] = ismember(A,B,'rows');
locs = accumarray(rowidx+1, (1:length(rowidx)).', [], @(v) {v});
ia = locs(2:end);
This needs to be a cell array because there are multiple results for some values.

추가 답변 (1개)

madhan ravi
madhan ravi 2018년 10월 27일
편집: madhan ravi 2018년 10월 27일
>> b=find(ismember(A,B,'rows'))'
b =
2 7 10 11
>>
  댓글 수: 2
madhan ravi
madhan ravi 2018년 10월 27일
use ismember() to get your desired result
UNK
UNK 2018년 10월 27일
Thanks, but I wanted the corresponding indices for each row of B.

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

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by