One approach assumes that A will be an input array N x 3 -
%
An example run at this input gives an output like -
out = [1] [1] [2x1 double] [1] [4] [ 16] [2] [3] [ 17] [3] [3] [ 87] [4] [4] [ 55] [5] [1] [ 110] [6] [2] [3x1 double]
Or using arrayfun -
%// Find unique rows using the first two columns of A [unqA12,~,idx] = unique(A(:,1:2),'rows') %// Use arrayfun to do the groupings instead of accumarray this time out = [num2cell(unqA12) arrayfun(@(n) A(idx==n,3),1:max(idx),'Uni',0).']
Note that the order of the elements of the third column will not be preserved in the first approach, but the second approach will do this.
source share