Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: how to find unique rows and calculate the average.
Replies: 9   Last Post: Apr 12, 2013 6:31 PM

 Messages: [ Previous | Next ]
 Bruno Luong Posts: 9,822 Registered: 7/26/08
Re: how to find unique rows and calculate the average.
Posted: Apr 11, 2013 2:38 AM

>> c = {'3BAB38287PAPU' 234
'3BAB38287POLA' 456
'3BAB38287GAAF' 35
'3BAB38287PAPU' 232
'3BAB38287POLA' 406
'3BAB38287GAAF' 29}

c =

'3BAB38287PAPU' [234]
'3BAB38287POLA' [456]
'3BAB38287GAAF' [ 35]
'3BAB38287PAPU' [232]
'3BAB38287POLA' [406]
'3BAB38287GAAF' [ 29]

[id, ~, J] = unique(c(:,1));
[id num2cell(accumarray(J, [c{:,2}]', [], @mean))]

ans =

'3BAB38287GAAF' [ 32]
'3BAB38287PAPU' [233]
'3BAB38287POLA' [431]

% Bruno

Date Subject Author
4/9/13 Guest
4/9/13 dpb
4/10/13 Alan Hitch
4/10/13 dpb
4/10/13 dpb
4/11/13 Alan Hitch
4/11/13 dpb
4/12/13 dpb
4/10/13 Peter Perkins
4/11/13 Bruno Luong