I am transforming a 3d matrix into a 2d matrix. This is the shape transformation: [n x m x o] -> [n*o x m].
The elements of the matrices are row-related. Thus, it is required to have the same rows in the resulting matrix.
A = rand(2,2,3);
Doing this:
C = reshape(A, 2*3, 2);
is not keeping the rows in A.
So I do this:
B = zeros(size(A,1)*size(A,3),size(A,2));
first_indice = 1;
for i = 1:size(A,3)
B(first_indice:size(A,1)*i,:)=A(:,:,i);
first_indice = first_indice + size(A,1);
end
Is there a more efficient way maybe using reshape?
Thanks a lot!