Extracting and saving data from different .cdf files

7 Ansichten (letzte 30 Tage)
Thishan Dharshana Karandana Gamalathge
Kommentiert: Walter Roberson am 18 Aug. 2017
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 Kommentare
per isakson
per isakson am 17 Aug. 2017
Bearbeitet: per isakson am 17 Aug. 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 am 18 Aug. 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.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Walter Roberson
Walter Roberson am 18 Aug. 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.

Tags

Noch keine Tags eingegeben.

Community Treasure Hunt

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

Start Hunting!

Translated by