ismember for many datasets
6 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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?
0 Commenti
Risposta accettata
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)))))))
0 Commenti
Più risposte (1)
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
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.
Vedere anche
Categorie
Scopri di più su Logical in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!