|
"Ulrik Nash" <uwn@sam.sdu.dk> wrote in message <jpigtm$kmr$1@newscl01ah.mathworks.com>...
> Hi Everyone,
>
> Suppose I have the following matrix,
>
> A = [1 1 2 3 3 4 4 5 1 2;0.10 0.12 0.34 0.45 0.18 0.34 0.27 0.65 0.48 0.31]
>
> Now I wish to create B, which is a 2 x 10 (in this case) matrix, which holds the minimum values in row 2 of A associated with the value in row 1 of A. So in the example above, the solution is:
>
> B = [1 2 3 4 5;0.10 0.34 0.18 0.27 0.65]
>
> How might this be done?
[u, I, J]=unique(A(1,:));
minA = accumarray(J(:),A(2,:)',[],@min);
B = [u; minA']
% Bruno
|