ismember for many datasets

조회 수: 5 (최근 30일)
joseph Frank
joseph Frank 2012년 5월 19일
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에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by