Function to pull 110 years of data from .nc files?

I'm trying to write a function that does the following:
metdriver=ncread('shtfl.2006.nc', 'shtfl');
but for my entire 110 year dataset(1900-2010).
Ideally the end result would be:
metdriveryear, with that year's data.
Any ideas? I'm new to .nc files, and it's taking some rethinking. Thanks a bunch!

Respuestas (1)

Sean de Wolski
Sean de Wolski el 25 de Jun. de 2013

1 voto

8 comentarios

Kate
Kate el 25 de Jun. de 2013
Thanks, but there needs to be an intermediary step because I need to pull my variables from the .nc files before I can do this.
Sean de Wolski
Sean de Wolski el 25 de Jun. de 2013
Stack the variables from each file into a cell-array. Then concatenate it.
So you right now have 110 files
shtf1.1900.c, shtf2.1901.nc
etc. right? And you need to grab a variable from each and store it?
Exactly, so individually extract the variables from the .nc files?
Example:
metdriver2006=ncread('shtfl.2006.nc', 'shtfl');
there's no way to do this all at once with a for loop or anything?
Kate
Kate el 25 de Jun. de 2013
I'm trying to come up with a function because I have 5 sets of 110 year data.
Kate
Kate el 25 de Jun. de 2013
oh, and to clarify, the file names are things like shtfl.1900.nc, shtfl.1901.nc, shtfl.1902.nc
Yes, so you'll want to use a cell-array. For example:
metdrivers = cell(110,1); %empty cell
years = 1900:2009
for ii = 1:110
metdrivers{ii} = ncread(['shtf1.' num2str(years(ii)) '.nc'],'shtf1');
end
Now you have a variable metdrivers that has all of the data for all of the years.
If you want the one for year 1900:
metdrivers{1}
With this you can then do anything!
Sean de Wolski
Sean de Wolski el 25 de Jun. de 2013
ps. this is pretty much exactly what the FAQ discusses.
I have a same question.I have daily nc files reading like this ncread('\','RF'); Now the name is 3B42_daily.1999.01.01.7.nc,3B42_daily.1999.01.02.7.nc,3B42_daily.1999.01.03.7.nc like that 2015.10.31.7.nc. In above code by Sean de Wolski what we have to change.

Iniciar sesión para comentar.

Categorías

Productos

Etiquetas

Preguntada:

el 25 de Jun. de 2013

Comentada:

el 22 de Mzo. de 2016

Community Treasure Hunt

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

Start Hunting!

Translated by