Getting the average of a vector
조회 수: 16 (최근 30일)
이전 댓글 표시
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 :)
댓글 수: 0
답변 (2개)
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
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
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().
참고 항목
카테고리
Help Center 및 File Exchange에서 Spreadsheets에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!