Hi all.
I have what I tink should be a fairly simple question but I just can't work it out. In one of my scripts I have a three-dimensional array A like this:
A(:,:,1) = 2 4 8 5 6 3 10 3 6A(:,:,2) = 7 6 3 9 2 9 10 2 3A(:,:,3) = 9 4 7 3 2 5 10 3 4
I also have a 2D matrix d which looks sth like this:
d = 1 2 3 1 1 3 2 1 1
Now, what I want to reduce A to two dimensions using the third dimension elements indicated by d. The result should be:
AA = 2 6 7 5 6 5 10 3 6
Surely there's a clever way to do this without loops? I fiddled around with a combination of meshgrid and d but that got ugly really quickly…
EDIT : I should have made clear that this is just an example and I don't necessarily know the dimensions of A. It will always be true that
size(A,1) == size(d,1)size(A,2) == size(d,2)
but A may be 5x5x13.
Thanks so much for your help.
Best Answer