0
$\begingroup$

I have a matrix:

`MT={{1, 54, 55}, {2, 841, 5}, {3, 6, 65}, {4, 28, 328}, {5, 188, 21}, {6, 2, 887}, {7, 36, 32}, {8, 7, 2}}`

And i need select the list which the 1st Raw WL={1,5,7,8}

The result will be {{1, 54, 55}, {5, 188, 21}, {7, 36, 32}, {8, 7, 2}}

But I want to save the executing time from the code:

Catenate[Table[ Select[MT, #[[1]] == WL[[i]] &], {i, Dimensions[WL][[1]]}]]

By this method, when Dimension[WL] too long, the executing time also become longer.

Does any method or function can easily save the executing time from this case?

$\endgroup$
  • $\begingroup$ MT[[WL]]will do it for your example. $\endgroup$ – ciao Sep 4 '19 at 6:18
2
$\begingroup$

You can use Cases

Cases[{Alternatives @@ WL, __}] @ MT

{{1, 54, 55}, {5, 188, 21}, {7, 36, 32}, {8, 7, 2}}

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.