MATLAB: Check the repeated values…count them and find mean

countmean

I have suppose 2 columns as follows:
1 22
2 44
1 88
5 100
7 200
2 600
8 45
9 76
7 24
4 54
what i want is: like 1 is repeated 2 times…now add the respective values from column 2 i.e 22 and 88 and add them and divide by 2(because 1 is occuring 2 times)..and do it for all values of column 1..i.e
1 (22+88)/2
2 (44+600)/2
5 (100)/1
7 (200+24)/2
8 (45)/1
9 (76)/1
4 (54)/1
please help me…i m stuck up with this problem… 🙁

Best Answer

The 'tm' you show in your code has only one column. When you write tm(:,2), matlab will complain. It looks as if you intended to join 'tm' and 's' together to form a two-columned 'tm'. Either that, or the code I wrote should use tm and s instead of tm(:,1) and tm(:,2), respectively.