I need to be able to return the indices [x1 x2 ... xd] of the elements of a matrix of dimensions LxLxL..xL. The number of dimensions d is a variable supplied to my function. The matrix does not exist, instead I have a linear array of length L^d. For a given index i in the array, I would like to know the equivalent indices in the matrix. I can already do this using a simple for loop, but I am curious to know if I could use ind2sub somehow. The problem I have is that if I do
x=zeros(1,d)
x=ind2sub(L,i)
x is reassigned a single number and not an array of all subscripts. Is there a way of doing this?