How to average a column based on another column?
36 views (last 30 days)
Show older comments
Commented: Leon on 20 Feb 2014
For example, I have a two column data as below:
How do I get a two column data as below, with the left column being the unique numbers: 1945, 1952, 1957, and the second column being the average values of that year:
I can write a loop to do this, but think it must have an easier way to do this.
Matt Kindig on 20 Feb 2014
This is a good use of accumarray():
output = [ud, accumarray(iy,data(:,2),,@mean)];
More Answers (0)
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!