This should be a fairly simple question to answer, but I am interested to hear some unique ways to do it, so here goes. I am using Matlab, but a viable C# solution would work for me as well.
I have an array (23000 rows x 3 columns). Each row is a combination of 3 values from a set of 90 values. I would like select a subset of these 90 values, say 10, and find the rows in which ANY 3 of these 10 values are members, and return the row number.
Now, I could generate a list of all the 3-value combinations of those 10 values, and then use ismember
in Matlab to find the row for each combination. But is there a different or more elegant way?
Alternately, I could use a=sum(ismember(array, 'value'),2)
to generate a logical vector where 'value'
occurs in array
, and use b=find(a)
to find the row indices where 'value'
occurs. I could do this for each value of the 10. But now the problem becomes, of these 10 lists of indices, which index occurs 3 or more times?
Any thoughts/comments/questions are appreciated. Thanks!
You were almost right with your suggestion of logical indexing.
Make value a vector with all the possible values:
Now you can use ismember on all the values at once.