Extracting and saving data from different .cdf files

6 visualizzazioni (ultimi 30 giorni)
I have a set of .cdf files inside which I have several variables which are common to each .cdf file. Each variable in different .cdf file has different amount of data. Rather than opening each .cdf file separately and extracting data for the variable of interest, I am looking a way to do it faster (probably using a loop) and save the results in a .mat file. Could you help me with that? Here is an example of how those .cdf file names look like and size of the variable I am interest at. Note that the file name contains the year, month, date (eg year 2010, month 10, day 15 for th 1st file). We can extract the data in first file as follows.
x1 = ncread('test.a1.20101015.000000.cdf', 'x');
test.a1.20101015.000000 size(x)= 86200x1
test.a1.20101016.000000 size(x)= 84000x1
test.a1.20101101.000000 size(x)= 85500x1
test.a1.20101102.000000 size(x)= 84890x1
Thanks a lot.
  2 Commenti
per isakson
per isakson il 17 Ago 2017
Modificato: per isakson il 17 Ago 2017
  • Why use ncread rather than cdfread, Read data from Common Data Format (CDF) file ?
  • Are the cdf-files in the same directory?
  • How (type of variable(s)) do you want to store the result?
  • "Note that the file name contains the year, month, date" How do you want to store the dates?
Walter Roberson
Walter Roberson il 18 Ago 2017
cdfread() is limited to the older original CDF format. ncread() can be used for those files and also for NETCDF files. cdfread() only supports 7-bit ASCII for attributes and comments.

Accedi per commentare.

Risposte (1)

Walter Roberson
Walter Roberson il 18 Ago 2017
netcdf files are structured binary files that you cannot simply fseek() into and pull out data. You will not be able to avoid using ncread or cdfread once for each file.
However, if you use a particular portion of the data multiple times, it might be worth reading the data from the files and storing them either as .mat or as binary files for performance reasons.

Tag

Non è stata ancora inserito alcun tag.

Community Treasure Hunt

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

Start Hunting!

Translated by