ismember for many datasets

6 visualizaciones (últimos 30 días)
joseph Frank
joseph Frank el 19 de Mayo de 2012
Hi,
I have many vectors sorted: A1,A2,.....A7
is it possible to know in one function which number is common between all of them for the first 10 rows? or do I need to use ismember between each individual pairs of vectors? or is there an easy way to do it?

Respuesta aceptada

Walter Roberson
Walter Roberson el 20 de Mayo de 2012
As we are told that these are vectors, and as rows are referred to, the implication is that they are column vectors. I rely on that in this code. I do not, however, rely upon the vectors being the same length (the code could possibly be shorter if they were)
intersect(A1(1:10), intersect(A2(1:10), intersect(A3(1:10), intersect(A4(1:10), intersect(A5(1:10), intersect(A6(1:10), A7(1:10)))))))

Más respuestas (1)

per isakson
per isakson el 20 de Mayo de 2012
This is a question for Cody :-)
Please check whether this one-liner does the job. I don't think there is the single function that does it.
The values must be integers, e.g. floating point integers. I cheated a bit by concatenating the column vectors to a matrix.
A = randi( 5, [ 30, 7 ] );
unique( A( arrayfun( @(k) (all(any(k==A(1:10,2:7)))), A(1:10,1)), 1 ) )
  1 comentario
Walter Roberson
Walter Roberson el 20 de Mayo de 2012
This appears to imply that the vectors all be the same length, which is not necessarily the case. On the other hand, only the first 10 rows are to be considered so one could logically concatenate just that part together.

Iniciar sesión para comentar.

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by