How do I create a for loop for averages?

I am trying to extract data from each column in order to produce averages for each year. i have posted an example of the script below:
year1 = RCP26(1,2:13);
year2 = RCP26(2,2:13);
year3 = RCP26(3,2:13);
average1 = mean(year1);
average2 = mean(year2);
average3 = mean(year3);
I need to create a for loop to create average for the years 1860-2100. when i try to do this i put in my for loop:
nYears = length(RCP26);
for i = 1:nYears
year(i) = RCP26(i,2:13);
end
however that does not work and im not sure why.

 採用された回答

Ameer Hamza
Ameer Hamza 2020 年 11 月 18 日
編集済み: Ameer Hamza 2020 年 11 月 18 日

1 投票

No need to use for-loop
averages = mean(RCP26(:,2:13), 2)
See the dim argument to mean() function: https://www.mathworks.com/help/matlab/ref/mean.html

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

質問済み:

2020 年 11 月 18 日

編集済み:

2020 年 11 月 18 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by