Monday, July 27, 2009

Matlab: indexing matrix of unknown number of dimensions

OP here.

Q:

If I know a multidimensional matrix x has 4 dims, I can index the first "row" of x using

x(1,:,:,:)


but how do I do this if I don't know ndims beforehand?

A:
c(1:ndims(x)-1)={':'};
x(1,c{:})

No comments: