How do i create a loop finding the mean value of many variables?
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Andrei Bobrov
el 2 de Dic. de 2016
Please attach small example of the your data. And example of the expected result.
Guillaume
el 2 de Dic. de 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.
Respuestas (1)
Vishal Neelagiri
el 5 de Dic. de 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
0 comentarios
Ver también
Categorías
Más información sobre Multidimensional Arrays en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!