I have a three dimensional array and I find the maximum value and indices of these values along the third dimension. How do I use these indices to find the values at the corresponding locations in another array of the same dimensions,
For example:
x = randn(5,10,20)[xmax,ixmax]=max(x,[],3);% ixmax is a 5 x 10 array that has the indices of the maxima along the third dimension of x
y = randn(5,10,20);% I want to find the values of y at the locations of the maxima of x
% I can of course do it by looping
for ii = 1:5 for jj = 1:10 yxmax(ii,jj)=y(ii,jj,ixmax(ii,jj)); endend
How do I do this without looping?
Best Answer