Comparing all the elements of an array with all the elements of another array
Mostrar comentarios más antiguos
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]
Respuesta aceptada
Más respuestas (1)
Ameer Hamza
el 20 de Oct. de 2020
Try this
C = A(ismember(A,B))
3 comentarios
Bruno Luong
el 21 de Oct. de 2020
Change statement
ismember(...)
to
ismembertol(..., 2, 'DataScale', 1)
Categorías
Más información sobre Workspace Variables and MAT Files en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!