Ok, this is a bit related, but you can get the indices of all the highs, and then randomly select one using randi
and accumarray
:
%# (1) Find the maxima %# if you are interested in the global maximum %# that may occur multiple times along dimension 6 [maxVal,maxIdx] = max(Defender.Q(:)); %# ALTERNATIVELY %# if you are interested in local maxima along dimension 6 maxVal = max(Defender.Q,[],6); maxIdx = find(bsxfun(@eq,Defender.Q,maxVal)); %# (2) pick random maximum for each 5D subarray %# this assumes that there is no dimension
source share