필터 지우기
필터 지우기

Getting the average of a vector

조회 수: 16 (최근 30일)
Maeve  Ryan
Maeve Ryan 2011년 11월 26일
Hello, I want to find the average daily precipitation over a year. I am given the rainfall recorded every 30 mins i.e. there are 48 readings per day. I am trying to find the average per day. However, the code I am using does not take into account the zero readings i.e. it does not include the times when there was zero precipitation over a 30 minute period.This results in the average daily rain being overestimated
Additionally, if the rainfall is zero over a particular day, i want this to be represented by a zero in the output vector - Matlab tends to ignore zero values it seems.
Here is my code
e = xlsread ('KerryRainGaugedata2010.xls',1);
%Find average daily precipitation
for i = 1:48:17520
%f is precipitation
f = e(i:i+47, 8);
%g is mean daily precipitation
g(i) = (sum(f)./sum(f~=0));
end
g(g==0) = [];
Can anybody help?
Thanks :)

답변 (2개)

Wayne King
Wayne King 2011년 11월 26일
Hi Maeve, how about just reshaping the data so you have 48 rows by 365 columns, then just taking the mean of the columns?
x = randn(17520,1);
x = reshape(x,48,365);
% column is one day
xavg = mean(x);
plot(xavg); xlabel('Days');
  댓글 수: 2
Maeve  Ryan
Maeve Ryan 2011년 11월 26일
If I am not mistaken, randn produces an array of random numbers. I do not random numbers. I want to plot the data from the excel file. Any suggestions?
Wayne King
Wayne King 2011년 11월 27일
Maeve, I did not mean for you to use randn(). I was just giving you an example. Because I do not have your data, I cannot do an example with your data. However, if you read your data into MATLAB as a 17520x1 vector, then you can use the above. If it reads in as 1x17520, then just do
x = x';
and you can still use the above.

댓글을 달려면 로그인하십시오.


Image Analyst
Image Analyst 2011년 11월 26일
Is it a problem with your "zeros" actually being blank cells in your workbook. No rain was recorded for those dates so it just left the cell empty. If so, then you might have to get all three outputs of xlsread and handle the case where the cells in the raw return arg are empty using isempty().
  댓글 수: 1
Maeve  Ryan
Maeve Ryan 2011년 11월 26일
No there are no blank cells in the excel file. It says "0" when there is no rainfall. I want to plot the daily rainfall for the 365 days..do you know how I could do this?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by