From: Bruno Luong on
"Juliette Salexa" <juliette.physicist(a)gmail.com> wrote in message <hrkqfo$377$1(a)fred.mathworks.com>...

> Maybe this has something to do with UNIQUE() arranging the input elements in increasing order ?

UNIQUE returns the rows dictionary-sorted. However you can get the order where the (unique) rows appear from the original array in the second output. You just need to arrange the result S. Note that you must call UNIQUE with 'FIRST' option in order to force the second output to be the first meet if there are more than one:

f=[1 1 1 ;
1 1 3 ;
1 4 4 ;
2 1 1 ;
2 1 4 ;
2 4 4 ]; % still wonder what is the first column is doing here
A=rand(size(f,1),1);

[U I J] = unique(f(:,2:3),'rows','first'); % <- first option
S = accumarray(J,A(:));
% Rearrange
[I I] = sort(I);
S=S(I)

% Bruno