Calculating seasonal rainfall precentage from netcdf file

6 visualizzazioni (ultimi 30 giorni)
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!! ;)
  1. The matrix is 708 x 1 so I need to tell Matlab that, from the top, every set of 12 numbers is a year
  2. then I need to add up all the values within each year for a total (annual precipiation)
  3. Followed by adding up every value at 7,8,9 within the 12 number block (year).
  4. Calculate % of summer rainfall, which should be JAS / annual for each year
  5. 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

Risposte (1)

Jyotish Kumar
Jyotish Kumar il 29 Mag 2019
Modificato: Jyotish Kumar il 29 Mag 2019
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.

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by