Advertisement
simonjtyler

Position2D

Dec 2nd, 2011
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. (* http://stackoverflow.com/questions/8364804 *)
  2.  
  3. Position2D[bigMat_?MatrixQ, smallMat_?MatrixQ] :=
  4. Module[{pos, sdim = Dimensions[smallMat] - 1},
  5. pos = Position[bigMat, smallMat[[1, 1]]];
  6. Quiet[Select[pos, (MatchQ[
  7. bigMat[[Sequence@@Thread[Span[#, # + sdim]]]], smallMat] &)],
  8. Part::take]]
  9.  
  10. (* Example *)
  11.  
  12. Position2D[{{0, 1, 2, 3}, {1, 2, 3, 4}, {2, 3, 4, 5}, {3, 5, 5, 6}},
  13. {{2, 3}, {3, _}}]
  14.  
  15. (* Returns: {{1, 3}, {2, 2}, {3, 1}} *)
  16.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement