matlab multiple dimensional indexing

Consider the array

 Arr = [a; b; c; d],

where a/b/c/d are all arrays of size n.

And I have either an array like

index = [1 3 4 2 3 1...]

or

[
[1 0 0 0 0 1 ....]
[0 0 0 1 0 0 ....]
[0 1 0 0 1 0 ....]
[0 0 1 0 0 0 ....]
]

And I want to get out of this

[a; c; d; b; c; a ...]

How would I use indexing (either logical or otherwise) to do this.

I would like something like Arr(index)

but that obviously doesn't do what I want it to.

Upvotes: 0

Views: 61

Answers (1)

Dan455
Dan455

Reputation: 352

For the first one:

[Arr(index,:)]

For the second one:

[index,~,~] = find(index);
[Arr(index,:)]

Upvotes: 2

Related Questions