Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (* http://stackoverflow.com/questions/8364804 *)
- Position2D[bigMat_?MatrixQ, smallMat_?MatrixQ] :=
- Module[{pos, sdim = Dimensions[smallMat] - 1},
- pos = Position[bigMat, smallMat[[1, 1]]];
- Quiet[Select[pos, (MatchQ[
- bigMat[[Sequence@@Thread[Span[#, # + sdim]]]], smallMat] &)],
- Part::take]]
- (* Example *)
- Position2D[{{0, 1, 2, 3}, {1, 2, 3, 4}, {2, 3, 4, 5}, {3, 5, 5, 6}},
- {{2, 3}, {3, _}}]
- (* Returns: {{1, 3}, {2, 2}, {3, 1}} *)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement