Calculating seasonal rainfall precentage from netcdf file
1 次查看(过去 30 天)
显示 更早的评论
Hey all,
Disclaimer- I am really new at MatLab so please forgive my ignorance (trying real hard to learn). MatLab 2017b
Here is my issue- I have downloaded a netcdf file (attached file) that contains monthly observations of precipitation from 1932-1991. What I need to do is calculate the percentage of rain that falls in the summer (July, August, September). I am beginning to set the problem up set-by-step so any help would be super awesome!! ;)
- The matrix is 708 x 1 so I need to tell Matlab that, from the top, every set of 12 numbers is a year
- then I need to add up all the values within each year for a total (annual precipiation)
- Followed by adding up every value at 7,8,9 within the 12 number block (year).
- Calculate % of summer rainfall, which should be JAS / annual for each year
- Finally, average each year's summer rainfall.
This is for the purpose of saying from 1932-1991 the average % of rain that fell during the summer was x (should be around 40-50% as I have calculated several years by hand)
I can do this for a single year using super simple indexing, but how I get this to repeat and scale this up to a large data set is where I am stuck
0 个评论
回答(1 个)
Jyotish Kumar
2019-5-29
编辑:Jyotish Kumar
2019-5-29
Hi,
First, you can reshape your matrix X (which is 708*1)
Y=reshape(X, [12,59]);
Find sum of all the 59 columns which will give you Sum of all 12 months rainfall for every 59 year
S=sum(Y, 1);
Now initialize a matrix with Zeros of size 1*59 and compute sum of (July, August, September) rainfall for every 59 year.
A=zeros(1,59);
for i=1:59
A(i)= sum(Y(7:9, i));
end
Now calculate Percentage of (July, August, September) rainfall over year for all 59 year.
P=A./S;
Calculate average of percentage
Avg= sum(P)/59;
I hope, it helps you to solve your problem.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 NetCDF 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!