I will convert a 3d matrix to a 2d matrix. This is a form conversion: [nxmxo] → [n * oxm].
Matrix elements are connected row by row. Thus, the resulting matrix requires the same rows.
A = rand(2,2,3);
Performing this action:
C = reshape(A, 2*3, 2);
does not save rows in A.
So, I am doing 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, possibly using a shape change?
Thanks a lot!
source share