How do i create a loop finding the mean value of many variables?

2 次查看(过去 30 天)
I was given an assignment to find the mean value for the percentage ice coverage on a lake for each day recorded over 6 years( 2010-2015). Since there are about 150-200 days to find this value for, I would like to use a loop, but I'm unsure of how I would make a loop that would do this.
An example of my data is for day 365 on lake erie i have values of 10.11, 12.02, 22.03, 15.06, 14.33, 16.66 for 2010-2015 respectively. The expected result for this day would be 15.035(add up all the values and divide by the number of values.)
  2 个评论
Andrei Bobrov
Andrei Bobrov 2016-12-2
Please attach small example of the your data. And example of the expected result.
Guillaume
Guillaume 2016-12-2
Since there are so many days to find this value for, I need to use a loop
Probably not. In fact, it's probably harder to do it with a loop. However, since you haven't specified what sort of form your input data takes, it's difficult to say.

请先登录,再进行评论。

回答(1 个)

Vishal Neelagiri
Vishal Neelagiri 2016-12-5
Let's assume that you have 200 days per year that you would like to find this average value for. You need to first organize this data into a 200*5 array where each column represents the ice coverage for all the 200 days in a particular year. So, the rows represent the days (200) and the columns represent the years (2010-2015, that is 5). Once this is done you can use the following code to calculate the average value for a particular day:
% Assume the variable ice_data is a 200*5 array consisting of the data
avg_value = mean(ice_data,2);
% This calculates the mean of each row in the ice_data variable and stores it in avg_value matrix
You can refer to this documentation link for additional information on the mean function:
https://www.mathworks.com/help/matlab/ref/mean.html

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by