replicating a matrix in the 3rd dimension in scilab
I'd like to replicate an NxM ma开发者_StackOverflowtrix into an NxMx3 matrix, i.e. have 3 copies of the input matrix in the third dimension. How do I do that?
If A is your NxM matrix, then the NxMx3 matrix is:
B = hypermat([size(A), 3], kron(ones(3, 1), A(1:$)))
or
B = hypermat([size(A), 3], ones(3, 1).*.A(1:$))
Here is a better and simpler answer (without using any operator):
B = A(:,:,[1 1 1])
Example (two copies are enough here):
-> a=[1 2;3 4]
a =
1. 2.
3. 4.
--> a(:,:,[1 1])
ans =
(:,:,1)
1. 2.
3. 4.
(:,:,2)
1. 2.
3. 4.
精彩评论