Extracting and saving data from different .cdf files

7 次查看(过去 30 天)
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 个评论
per isakson
per isakson 2017-8-17
编辑:per isakson 2017-8-17
  • 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 2017-8-18
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.

请先登录,再进行评论。

回答(1 个)

Walter Roberson
Walter Roberson 2017-8-18
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.

标签

尚未输入任何标签。

Community Treasure Hunt

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

Start Hunting!

Translated by