- Convert your time into datevec. This will give you day, month, year etc.
- Run loop for each month.
- Pick the months indices from time. Like use: idx = month == 1 (this will pick Jan)
- Pick the data using the baove indices idx. Like use: data_jan = data(:,:,idx) ;
- Convert the above 3D data into 2D. Use
How to add vertical values in three dimensional matrix
1 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
KSSV
2021-6-1
编辑:KSSV
2021-6-1
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 个评论
更多回答(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!