MATLAB: Find duplicate entries and average associated values

averagefindMATLAB

Hi all,
I have a 180 x 2 array of data and in the first column there are some repeated values (multiple data points at the same location). With those repeated values I'd like to average the associated data in column 2. Any help with this would be appreciated greatly.
Example array: [1 10; 2 20; 3 30; 4 40; 4 50; 4 60; 5 70; 6 80; 7 90; 7 100; 8 110]
I'd like to create a new array that looks like this: [1 10; 2 20; 3 30; 4 50; 5 70; 6 80; 7 95; 7 100; 8 110]
Thanks a ton for any help.
-Chris

Best Answer

array = [1 10; 2 20; 3 30; 4 40; 4 50; 4 60; 5 70; 6 80; 7 90; 7 100; 8 110];
[C,ia,idx] = unique(array(:,1),'stable');
val = accumarray(idx,array(:,2),[],@mean);
your_mat = [C val]