Search code examples
scilab

replicating a matrix in the 3rd dimension in scilab


I'd like to replicate an NxM matrix into an NxMx3 matrix, i.e. have 3 copies of the input matrix in the third dimension. How do I do that?


Solution

  • 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:$))