Andi
Andi

Reputation: 4899

MATLAB: Reshape every slice of a 3D matrix

Is it possible to reshape every slice of a 3D matrix using vectorization rather than the following for-loop-solution?

orig3D = rand(228,1,2);

for n = 1 : 2
    new3D(:,:,n) = reshape(orig3D(:,:,n), [12,19])';
end

Upvotes: 2

Views: 62

Answers (1)

Divakar
Divakar

Reputation: 221704

Reshape and permute -

new3D = permute(reshape(orig3D, 12,19,[]),[2,1,3])

Upvotes: 3

Related Questions