开发者

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.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜