ismember for many datasets

2 次查看(过去 30 天)
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?

采纳的回答

Walter Roberson
Walter Roberson 2012-5-20
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)))))))

更多回答(1 个)

per isakson
per isakson 2012-5-20
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 个评论
Walter Roberson
Walter Roberson 2012-5-20
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Tables 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by