How to find the intermediate elements of the sub-matrices in a matrix

advertisements

I have a matrix and i want to consider it has 4 sub matrices which are placed together. How can I find the middle element of each sub matrix when they are together?

consider the matrix below. It is built by 4 sub matrices.

1  2  3  4   5  6
7  8  9  10 11 12
13 14 15 16 17 18
19 20 21 22 23 24
25 26 27 28 29 30
31 32 33 34 35 36

I want to get their middle elements so i could have:

 8, 11, 26, 29


From what I have understood this might work for you and this is a demo, so use your own parameters -

Code

%%// Input matrix
A = rand(44,44);

%%/ Number of submatrices needed
num_submat = 16;%%// 4 for your example case

%%/ Number of submatrices along row and column
num_submat1= sqrt(num_submat);

%%// Middle element indices along each direction
v1 = floor(size(A,2)/(2*num_submat1))+1:size(A,2)/(num_submat1):size(A,2);

%%// Middle elements
middle_ele = A(v1,v1)