How to organize data in matrix

4 次查看(过去 30 天)
Hi, I have a dataset that is in netCDF format. These data are precipitation and have 5 variables. I reduced the 2D I need (lat, lon) and now I need to save to a 3D cell with fixed lat and lon and time varying. I am unable to save so that they are not subscribed to previous data. Any help will be appreciated.
  4 个评论
John D'Errico
John D'Errico 2019-10-1
编辑:John D'Errico 2019-10-1
Sorry, but this is gibberish so far as you have written. You may understand what you are asking to do, but it makes no sense at all.
So give a SMALL, SIMPLE example, only a few numbers. Then show what you would hope to find as a result.
There is no need to even post a netcdf file, as that just means you have not read it into MATLAB yet. It is just a bunch of numbers.
If you want help, then make it easy for somone to help you.
Stephen23
Stephen23 2019-10-2
FELIPE PIMENTEL's "Answer" moved here:
Sorry it was not clear.
I have files in netCDF format with the following variables:
netcdf4_classic
Dimensions:
S = 1
M = 10
Y = 181
X = 360
L = 7
Variables:
S
Size: 1x1
Dimensions: S
Datatype: double
Attributes:
units = 'months since 1982-01-01'
calendar = 'standard'
axis = 'N'
M
Size: 10x1
Dimensions: M
Datatype: single
Attributes:
units = 'Unitless'
long_name = 'Ensemble Member'
axis = 'M'
Y
Size: 181x1
Dimensions: Y
Datatype: single
Attributes:
units = 'degrees_north'
long_name = 'latitude'
axis = 'Y'
X
Size: 360x1
Dimensions: X
Datatype: single
Attributes:
units = 'degrees_east'
long_name = 'longitude'
axis = 'X'
L
Size: 7x1
Dimensions: L
Datatype: single
Attributes:
units = 'months'
long_name = 'Lead'
standard_name = 'forecast_period'
axis = 'L'
pr
Size: 360x181x7x10x1
Dimensions: X,Y,L,M,S
Datatype: double
Attributes:
units = 'mm'
long_name = 'Precipitation'
missing_value = -999
fill_value = -999
For "M", I have a mean and for "L" I select 1, 2 or 3 as needed. I need to open these files one by one, select lat and lon for South America and write in a continuous matrix with monthly data from 1982/jan to 2010/dec.
That is, I need an organized 3D matrix like lat, lon and monthly interval precipitation. That way my matrix would be 60x45x348 (lat x lon x time) All the part of selecting and extracting the data I am doing. The problem is saving these files to a new array because I'm overwriting over the previously read data and the array ends up as 2D with the last read data.

请先登录,再进行评论。

回答(1 个)

meghannmarie
meghannmarie 2019-10-3
Did you preallocate output array?
output_array = nan(60,45,348);
for time_idx = 1:348
output_array(:,:,time_idx) = ncread(file,'pr',start,count);
end
  1 个评论
FELIPE PIMENTEL
FELIPE PIMENTEL 2019-10-3
Thank you very much.
That was exactly what I was looking for.
Thanks

请先登录,再进行评论。

标签

产品


版本

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by