필터 지우기
필터 지우기

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

조회 수: 2 (최근 30일)
Eddie Bazinet
Eddie Bazinet 2016년 12월 2일
답변: Vishal Neelagiri 2016년 12월 5일
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