I recommend using Pick for these things. It has already been used by others but the simplest form using Alternatives hasn't been shown:
Pick[#, #[[All, 1]], Alternatives @@ #2] &[mymatrix, compvector] {{1, 1, -56}, {1, 2, 3.06}, {2, 0, -30.02}, {6, 1, 9.945}, {7, 0, -7.512}}
For greater speed especially with longer comvectors we can use a Dispatch table:
fast[m_, c_] := Pick[m, m[[All, 1]] /. Dispatch @ Thread[c -> True]] fast[mymatrix, compvector] {{1, 1, -56}, {1, 2, 3.06}, {2, 0, -30.02}, {6, 1, 9.945}, {7, 0, -7.512}}
Timings with some larger data:
mymatrix = RandomInteger[9999, {50000, 3}]; compvector = RandomChoice[Range@9999, 150]; (* the faster of Michael's functions *) michael[m_, c_] := With[{nf = Nearest[c]}, Pick[m, # - First /@ nf /@ # &@m[[All, 1]], 0] ] michael2[m_Cases[mymatrix, c_] :={x_, Pick[m_, Times_} @@@/; Outer[PlusMemberQ[compvector, m[[All,x]] 1]],// -c],Timing 0] // First Pick[#, #[[All, 1]], Alternatives @@ #2] &[mymatrix, compvector] // Timing // First Cases[mymatrixmichael[mymatrix, {x_,compvector] _, _} /; MemberQ[compvector, x]] // Timing // First michael[mymatrix, compvector] // Timing // First michael2[mymatrixfast[mymatrix, compvector] // Timing // First 03.094447
0.39905
0.094265
0.765047
The length of compvector was chosenA run-off with care; shorter vectors favor my method, while longer ones favor Michael's first function.method on even larger data:
mymatrix = RandomInteger[99999, {500000, 3}]; compvector = RandomChoice[Range@99999, 15000]; michael[mymatrix, compvector] // Timing // First fast[mymatrix, compvector] // Timing // First 15.943
0.327