ismember for many datasets

1 visualizzazione (ultimi 30 giorni)
joseph Frank
joseph Frank il 19 Mag 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?

Risposta accettata

Walter Roberson
Walter Roberson il 20 Mag 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)))))))

Più risposte (1)

per isakson
per isakson il 20 Mag 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 Commento
Walter Roberson
Walter Roberson il 20 Mag 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.

Accedi per commentare.

Categorie

Scopri di più su Tables in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by