Effacer les filtres
Effacer les filtres

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

2 vues (au cours des 30 derniers jours)
Eddie Bazinet
Eddie Bazinet le 2 Déc 2016
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 commentaires
Andrei Bobrov
Andrei Bobrov le 2 Déc 2016
Please attach small example of the your data. And example of the expected result.
Guillaume
Guillaume le 2 Déc 2016
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.

Connectez-vous pour commenter.

Réponses (1)

Vishal Neelagiri
Vishal Neelagiri le 5 Déc 2016
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

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by