Given a vector v = [1 2 3 4 5 6] how do I turn it into:
v =
v(:,:,1) = 1
v(:,:,2) = 2
v(:,:,3) = 3
v(:,:,4) = 4
v(:,:,5) = 5
v(:,:,6) = 6
i.e., transpose between the second (row) and third dimension?
The answer is to use the permute command:
permute([1 2 3 4 5 6], [3 1 2])
It accepts non-existing dimensions: the second argument specifies swapping the first existing dimension with the third existing dimension (none), which creates a 'singleton' first dimension in the result.
You can also reshape:
reshape([1 2 3 4 5],1,1,[])
EDIT (in response to comment): actually, it does:
>> reshape([1 2 3 4 5],1,1,[])
ans(:,:,1) =
1
ans(:,:,2) =
2
ans(:,:,3) =
3
ans(:,:,4) =
4
ans(:,:,5) =
5
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With