我从1958年到2016年有几年的数据。我想绘制年平均值与年份的关系。有没有比我做过的更简单的方法?
%Want to make an array of annual averages
avg = [];
for n = 1958:2016
sum = 0;
year_counter = 0;
%there are 708 observations
for k = 1:708
%if the year matches, look up the corresponding value and add it to the sum
if data(k, 1) == n
sum = sum + data(k,2);
year_counter = year_counter + 1;
end
end
%append the average to the array
avg = [avg s/year_counter];
end