Возможно, есть более эффективный способ сделать это, но, похоже, это сработало.
Input = [
5 2 5;
2 1 2;
4 3 2;
5 3 3;
5 2 4;
4 2 3;
1 1 3;
4 5 1;
3 3 1;
2 1 4;
2 3 1;
4 2 4
];
% Make input matrix into 1x36 vector to preserve ordering
InputAsSingleRow = reshape(Input', [], 1);
% Reshape into 4x9 matrix
Output = reshape(InputAsSingleRow,[4,9]);
% Reshape into 4x3x3 matrix you wanted
Output2 = reshape(Output,[4,3,3])
Результат:
Output2 =
ans(:,:,1) =
5 1 2
2 2 5
5 4 3
2 3 3
ans(:,:,2) =
5 2 3
2 3 4
4 1 5
4 1 1
ans(:,:,3) =
3 1 1
3 4 4
1 2 2
2 3 4