> Initially I hoped that some 'simple' sub2ind / ind2sub trick exist to solve the problem. If the max function provides imax, I expected a simpler access to the max values in Di. :-)
It's possible to use sub2ind but it will waste more memory since a lot of temporary variables are created:
% Engine
s = size(Di);
if length(s) < dim
s(dim) = 1;
end
c = arrayfun(@(n) 1:n, s, 'unif', 0);
c{dim} = 1;
[c{:}] = ndgrid(c{:});
[maxDi,c{dim}] = max(Di,[],dim);
ilinmax = sub2ind(s,c{:});