How to add vertical values in three dimensional matrix

조회 수: 2 (최근 30일)
Suman Dhamala
Suman Dhamala 2021년 6월 1일
댓글: KSSV 2021년 6월 1일
I have a netcdf file, with following details. The variable 'rf' is gridded rainfall value, and it is basically daily rainfall data from 1901 to 2018, resulting to 43099 values. When i read this netcdf file and assigned a variable for gridded rainfall, then my matrix was 135*129*43099, 135*129 being the number of grids, with each grid having 43099 values. I want to convert this daily rainfall data to monthly rainfall data, by adding the one month value to get a single value and get 12 values a year and get total 1416 values for all time period, considering all leap years and different number of days in a month. Hence my final resultant array should be 135*129*1416.
Dimensions:
time = 43099 (UNLIMITED)
lon = 135
lat = 129
Variables:
time
Size: 43099x1
Dimensions: time
Datatype: double
Attributes:
standard_name = 'time'
units = 'hours since 1-1-1 00:00:00'
calendar = 'standard'
axis = 'T'
lon
Size: 135x1
Dimensions: lon
Datatype: single
Attributes:
standard_name = 'longitude'
long_name = 'longitude'
units = 'degrees_east'
axis = 'X'
lat
Size: 129x1
Dimensions: lat
Datatype: single
Attributes:
standard_name = 'latitude'
long_name = 'latitude'
units = 'degrees_north'
axis = 'Y'
rf
Size: 135x129x43099
Dimensions: lon,lat,time
Datatype: single
Attributes:
long_name = 'GRIDDED RAINFALL'
_FillValue = -999
missing_value = -999

채택된 답변

KSSV
KSSV 2021년 6월 1일
편집: KSSV 2021년 6월 1일
  1. Convert your time into datevec. This will give you day, month, year etc.
  2. Run loop for each month.
  3. Pick the months indices from time. Like use: idx = month == 1 (this will pick Jan)
  4. Pick the data using the baove indices idx. Like use: data_jan = data(:,:,idx) ;
  5. Convert the above 3D data into 2D. Use
T = permute(data_jan,[1 3 2]);
T = reshape(T,[],size(data_jan,2),1) ;
5. The above 2D matrix is for Jan for all the years.
6. You can process it.
There are some inbuilt functions also to achieve this. I don't remember the function name and I have never used too.
  댓글 수: 2
Suman Dhamala
Suman Dhamala 2021년 6월 1일
I created a time vector with number of rows being equal to number of days, like in one column year, in another month and in another day. But since, this time vector and gridded rainfall are two different matrices, how do i link them, so that while running loop for time vector, I can add rainfall vaues for each grid?
KSSV
KSSV 2021년 6월 1일
I already shown you how to index right? Step 3 and step 4.

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

추가 답변 (0개)

태그

Community Treasure Hunt

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

Start Hunting!

Translated by