|
Wolfgang Schwanghart wrote:
> A = accumarray(ind,val,[3 1],@findmax)
>
> A =
>
> 1
> 2
> 2
>
> I don't know what A is telling me now but obviously it is
> not what I wanted.
It may not be what you wanted, but it is waht you asked for. To see why, do this:
>> A = accumarray(ind,val,[3 1],@(x) {x})
A =
[3x1 double]
[3x1 double]
[3x1 double]
>> A{:}
ans =
0.7
0.4
0.1
ans =
0.5
0.8
0.2
ans =
0.3
0.9
0.6
accumarray has returned the index _within the first group_ of the max of the
first group, and so on.
> I want A to be
>
> A = [7 8 9]';
You're asking accumarray to compute a function that cannot be computed using
only using the values in each of the groups -- to compute what you want, you
also need to know the positions in the original data, and that information is
lost by the time the information gets to your findmax function.
You could take the output that you got using @max, and do a series of finds on
the original data.
Or, and I'm not saying that I recommend this, here's a too-clever way to use an
input that encodes both the value, and the position:
val2 = complex(val,(1:9)');
>> A = accumarray(ind,val2,[3 1],@tmp)
A =
7
8
9
where
function y = tmp(x)
[dum,i] = max(real(x));
y = imag(x(i));
|