Comparing all the elements of an array with all the elements of another array
15 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello ,
I want to compare Compare all the elements of an array with all the elements of another array and save the result to a now array.
i have an array A=[100 110 120 130.....600]
which i want to compare with B = [100 103 105 120 123 128 130 200 205 207 300 200 100 ]
if the value of B mateches with any element of array the value of A sholud be stored in new array C and the value should not repeal(like if there is already 100 in the array C then i should not write it again. )
the output should look like this
C = [100 120 130 200 300]
0 Kommentare
Akzeptierte Antwort
Bruno Luong
am 20 Okt. 2020
Bearbeitet: Bruno Luong
am 20 Okt. 2020
This returns the elements in order as in B, from left to right
A = 100:10:600
B = [100 103 105 120 123 128 130 200 205 207 300 200 100 ]
C = unique(B(ismember(B,A)),'stable')
0 Kommentare
Weitere Antworten (1)
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!