MATLAB: Extract sub-matrices from a big matrix

MATLABmatrix manipulation

I have an example matrix like the one given below. Original size of my matrix is (83193 x 2). I want extract every 2 rows and make a 2 x 2 matrix from this big matrix. For example:
[1 2
3 4
5 6
7 8
9 10
11 12]
Changed into:
A = [1 2; 3 4]
B = [5 6; 7 8]
C = [9 10; 11 12]
How can I do this operation?
Thanks!

Best Answer

X = rand(83193, 2);
s1 = size(X, 1);
XX = X(1:s1 - rem(s1, 2), :); % Number of blocks needs to be multiple of 2
Y = permute(reshape(XX, 2, [], 2), [1, 3, 2]);
Now Y(:, :, i) is the i.th 2x2 matrix. This is much more efficient than creating 41596 variables.