# How to get a sub range of a larger matrix?

This should be an easy question but I only found a partial solution using All.

Say I have a matrix A = 1000 x 5, how to get only a part of that matrix, say B = n x 5, where n can be any positive integer that's less than 1000 or the original matrix A row?

-
Please have a good long look at Part (preferrably in conjunction with Span). –  Yves Klett Nov 11 '12 at 19:14
Could you please consider accepting some answers by clicking the checkmark sign ? –  chris Nov 11 '12 at 22:53
You might find this Q/A useful: How to extract and replace submatrix.... –  István Zachar Nov 12 '12 at 11:03

I guess this should work, if I need the second and third rows of a matrix :

{{a, b, c}, {d, e, f}, {g, h, i}}[[2 ;; 3]]

-

You can make good use of Span in multiple dimensions:

m = Table[{y, x}, {y, 1, 5}, {x, 1, 10}];

m[[2 ;; 3, 5 ;; 6]]


{{{2, 5}, {2, 6}}, {{3, 5}, {3, 6}}}

(verbatim @J.M.)...Take[] works nicely as well:

Take[m, {2, 3}, {5, 6}]


{{{2, 5}, {2, 6}}, {{3, 5}, {3, 6}}}

-
Take[] works nicely as well: Take[m, {2, 3}, {5, 6}] –  Guess who it is. Nov 12 '12 at 9:27
@J.M. another answer? Strangely, I almost never use Take` in my code... so much for cerebral plasticity. –  Yves Klett Nov 12 '12 at 13:50
I'd prefer that you just append it to your answer... :) –  Guess who it is. Nov 12 '12 at 14:03
@J.M. Ta(l)king about low-hanging fruit :-) –  Yves Klett Nov 12 '12 at 14:10