how to take a mean of specific rows
93 views (last 30 days)
hi. i have created a mat file which contains 42 rows and 7 number of columns 42 rows represent 42 months started from January.(3 years 6 months) i want to take a mean of all monthly values all January(rows 1,13,25,37) mean all feb (rows 2,14,26,38) like that for all months
so it would give me 12 rows and 7 columns.
hope you understand. any help will appreciable.
Image Analyst on 12 Sep 2017
Assuming you have, or can add, a column with the month number, then simply use grpstats(), if you have the Statistics and Machine Learning Toolbox.
monthlyMeans = grpstats(yourTable, monthColumn);
KL on 12 Sep 2017
Edited: KL on 12 Sep 2017
your_variable_mean_1 = mean(your_variable([1 13 25 37],:),1) %row-wise mean
your_variable_mean_2 = mean(your_variable([2 14 26 36],:),1)
your_variable_mean_1 = mean(your_variable([1 13 25 37],:),2) %column-wise mean
your_variable_mean_2 = mean(your_variable([2 14 26 36],:),2)
But this is not the ideal way, you should include month number in a column and create a table. Then you can use month as grouping variable and do your calculations in the proper way.