JaredL
JaredL

Reputation: 1443

Index a multi-dimensional array with a vector

In my script I am creating an array, the number of dimensions of which are not known in advance. I want to get a certain sub-matrix from the array. Typically with an array of a known number of dimensions I would just write array(i1, i2, i3, ... iN, :, :). However, the indices are contained in an array I = [i1, i2, i3, ... iN). How do I accomplish this?

Upvotes: 0

Views: 91

Answers (1)

juliohm
juliohm

Reputation: 3779

You can convert the index vector to a cell first:

A(num2cell(idx){:})

but there is probably a more elegant solution to that.

Upvotes: 1

Related Questions