|
"David Doria" <daviddoria@gmail.com> wrote in message <ge7q06$4k2$1@fred.mathworks.com>...
> I didn't see anything like on the file exchange, which really surprised me.
>
> I have a multidimensional array that I would like to query for the largest N values. ie if i say
>
> [v loc] = max(A, 2);
>
> where A is 3x3x10, I would like v to be length 2 containing the largest two values, and loc to be length 2 containing the positions of those values (a coordinate in the nXmXp space).
>
> Does someone know of a script like this that I just missed on the file exchange? It just seems like it would be terribly inefficient if I wrote it.
>
> Thanks,
>
> Dave
Hi Dave,
Just one of many solutions could look like (with A as you defined it):
A_col = reshape(A,[],1);
A_sort = sort(A_col,'descend');
v = A_sort(1:2);
lin_loc = find(A_col == v(1)); % for the first max
real_loc = ind2sub(size(A),lin_loc); % for the first max
Playing around with that will allow you to customize it.
|