"Bruno " <bruno.marchesi@gmail.com> wrote in message <gm7vmc$n1s$1@fred.mathworks.com>...
> Greetings,
>
> please consider the array:
>
> o =
>
> 1 2 5 4
> 1 3 2 9
> 1 3 2 4
> 2 3 4 10
> 2 3 4 7
> 2 3 4 5
> 5 1 2 8
> 5 1 2 2
> 5 1 2 9
> 5 2 6 8
>
> note that the 1st three columns are already sorted.
>
> The pursued function should take the array o and output an array y.
> Each line of o where the 1st 3 elements are equal to
> another line of o, the 4th is summed, but not the others.
> For example, the expected answer y for the array o should be:
>
> 1 2 5 4
> 1 3 2 13
> 2 3 4 22
> 5 1 2 19
> 5 2 6 8
>
> Is the problem clear?
>
> I sniff it would use find, sortrows, ismember, but I just can't
> get it done. It doesn't have to be solved in one line, but avoiding
> indexing/loop is surely good enough. SOS please ?
>
> Thanks,
> Bruno.
I would use my consolidator function on the
problem. Apply it to the first three rows,
forcing it to sum the 4th column as the
dependent value.
http://www.mathworks.com/matlabcentral/fileexchange/8354
[ou,osum] = consolidator(o(:,1:3),o(:,4),@sum);
oresult = [ou,osum];
HTH,
John
