I have a sorted array (8 integer elements) and a large matrix (10000, 9) and would like to know how many elements of my sorted array occur in each row of my matrix and put that count (for each row) in an integer array Present(10000)

Must i compare each element of my sorted array with each element of each row of my matrix (OK, I can do it "intelligent" and skip part of the comparisons), or does a function exist that allows me to do that more efficient. Ideal would be for the whole matrix at once of course.