MATLAB: How to do an average for certains values of a column

average columnsMATLABmatricemean

Let's say I have a matrice 4711×2.
The first Column is a year number (eg.2010)and the second column are values.
Some years only have one value, and other years have more than one value. When there is more thant one value I have to to do an average.
So at the end I need only one value for each year.
I hope it makes sense, english is not my mother tongue.
Thank you

Best Answer

I have done it wit some random data generated. You can follow the same procedure for your data.
A = randi(100,1000,2) ; % generate random data which repeats
years = A(:,1) ;
value = A(:,2) ;
[c,a,b] = unique(years) ;
iwant = zeros(length(c),2) ;
for i = 1:length(c)
idx = find(years==c(i)) ;
% get mean
iwant(i,:) = [c(i) mean(value(idx))] ;
end