Let's say I have a 3-dimensional
matrix and have computed the max
along the second dimension, and want to get the linear indices of the max values. However, the max-function
only returns the subscripts along one dimension.
A = randn([5,5,5]); % Generate random matrix
[M, Ind] = max(A,[],2); % Take the max along dimension 2
How do I transfer the index
to linear indexing
, such that
M == A(Ind)
becomes true?
My intention for this problem is that I have two
multi-dimensional
matrices and need to compute the max
in the first
one. Then, I want to access the values in the second
matrix at exactly those positions where I found a max in the first
one.