Thoth
Thoth

Reputation: 1041

Reshape 3d matrix in z direction

we have a = [1 2; 3 4]; and b = [5 6;7 8]; and z = cat(3,a,b). I want to vectorize the 3d matrix so the reresult would be c = [1 5; 2 6; 3 7; 4 8 ]? I know it is related to reshape but I can not find the way:)

Thanks.

Upvotes: 2

Views: 161

Answers (2)

Edric
Edric

Reputation: 25160

reshape(permute(z,[2 1 3]), 4, 2)

Upvotes: 3

Jonas
Jonas

Reputation: 74940

If you need to go via z:

c = reshape(permute(z,[2 1 3]),[],2)

Otherwise,

c = [reshape(a',[],1),reshape(b',[],1)];

Upvotes: 3

Related Questions