MATLAB: Take submatrix out of large matrix starting from a certain element

submatrix

Hi everyone,
I've got a large matrix, e.g. 1024×512 elements. What I would like to do is grap a submatrix of 32×32 from a random element such as element (100,312). That element would be the middle point of the submatrix (so take 15 elements to the right and below and take 16 elements to left and above).
I'd appreciate your help with this.
Cheers,
Stijn

Best Answer

A = rand(1024,512);
i0 = 100;
j0 = 312;
A_sub = A((i0-16):(i0+15),(j0-16):(j0+15));