Split a specific matrix in 4 equal parts

If I define the matrix as follows:
Given 4 matrix of equal dimensions, say A, B, C, D.
Let
E = [A B; C D];
May I do something like (totally pseudo-code):
B2 = E(B);
to retrieve the submatrix B without the use of cell arrays?

 Accepted Answer

KSSV
KSSV on 19 Jun 2020
Edited: KSSV on 19 Jun 2020
M = rand(8) ;
[m,n] =size(M) ;
A = M(1:n/2,1:n/2) ;
B = M(1:n/2,n/2+1:end) ;
C = M(n/2+1:end,1:n/2) ;
D = M(n/2+1:end,n/2+1:end) ;
But the best would be:
m =size(M,1)/2 ;
A = mat2cell(M,[m m],[m m]) ;
A{1,1}
A{1,2}
A{2,1}
A{2,2}

More Answers (0)

Categories

Asked:

on 19 Jun 2020

Edited:

on 19 Jun 2020

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!