Reputation: 1041
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
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