Average of subgroup of 2nd column, grouped by 1st column
问题 Suppose I have matrix A. 1st column is "group". Then I want to calculate the average of 2nd column for each group. So I want to create B. A= 1 2 1 3 2 4 2 2 B= 1 2.5 2 3 The best thing I did until now is to construct a long for and if loop and use average function to get to B. But I guess there will be more simple method. Is there? 回答1: I hadn't used accumarray before, so due to the comment by @Dan I decided to give it a try. At first I tried a naive version and used histc to count