How to find same unique in two different size arrays?

13 visualizaciones (últimos 30 días)
Assuming we have two different array sizes with similar items in it. How to find number of common items in these arrays?
for ex:
x=[1 22 22
3 8 19];
y=[22 10 19 35];
here answer must be 2, reffering to 22 and 19.
Any good ideas? And also, would that be possible to do it without using loop since actual data size is relatively big?

Respuesta aceptada

Fabio Freschi
Fabio Freschi el 1 de Jun. de 2022
Use ismember
% data
x=[1 22 22
3 8 19];
y=[22 10 19 35];
% engine
[iii,jjj] = ismember(y(:),x(:));
countCommon = sum(iii)
entryCommon = y(iii)

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by