Find common elements of two array with repetition????
Mostra commenti meno recenti
For example
A = [1234567]
B = [2348907]
now i hv to compare above two and want to store index of common elements.
Risposte (1)
[C,ia,ib] = intersect(A,B)
For example:
>> A = [1,2,3,4,5,6,7];
>> B = [2,3,4,8,9,0,7];
>> [C,ia,ib] = intersect(A,B)
C =
2 3 4 7
ia =
2 3 4 7
ib =
1 2 3 7
4 Commenti
div
il 11 Set 2018
@div: well, that is a different question. Try this:
>> A = [1,2,3,4,5,1,9];
>> B = [1,4,3,7,5,1,9];
>> C = A(A==B)
C =
1 3 5 1 9
>> X = find(A==B) % (but logical indices are usually more efficient)
X =
1 3 5 6 7
div
il 11 Set 2018
Image Analyst
il 11 Set 2018
It DOES work. I just copied and pasted and it worked fine. Post the code that you subsequently altered so we can see how your alterations ruined it.
Categorie
Scopri di più su Matrix Indexing in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!