How to find mutual arrays position of multiple matrices with different length
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
UNK
am 27 Okt. 2018
Kommentiert: UNK
am 27 Okt. 2018
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]?
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 27 Okt. 2018
[~, 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.
0 Kommentare
Weitere Antworten (1)
madhan ravi
am 27 Okt. 2018
Bearbeitet: madhan ravi
am 27 Okt. 2018
>> b=find(ismember(A,B,'rows'))'
b =
2 7 10 11
>>
2 Kommentare
Siehe auch
Kategorien
Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!