Documentation |
Read data from Common Data Format (CDF) file
data = cdfread(filename)
data = cdfread(filename, param1, val1,
param2, val2, ...)
[data, info] = cdfread(filename,
...)
data = cdfread(filename) reads all the data from the Common Data Format (CDF) file specified in the string filename. CDF data sets typically contain a set of variables, of a specific data type, each with an associated set of records. The variable might represent time values with each record representing a specific time that an observation was recorded. cdfread returns all the data in a cell array where each column represents a variable and each row represents a record associated with a variable. If the variables have varying numbers of associated records, cdfread pads the rows to create a rectangular cell array, using pad values defined in the CDF file.
data = cdfread(filename, param1, val1, param2, val2, ...) reads data from the file, where param1, param2, and so on, can be any of the parameters listed in the following table.
[data, info] = cdfread(filename, ...) returns details about the CDF file in the info structure.
Parameter | Value |
---|---|
'Records' | A vector specifying which records to read. Record numbers are zero-based. cdfread returns a cell array with the same number of rows as the number of records read and as many columns as there are variables. |
'Variables' | A 1-by-n or n-by-1 cell array specifying the names of the variables to read from the file. n must be less than or equal to the total number of variables in the file. cdfread returns a cell array with the same number of columns as the number of variables read, and a row for each record read. |
'Slices' | An m-by-3 array, where each row specifies
where to start reading along a particular dimension of a variable,
the skip interval to use on that dimension (every item, every other
item, etc.), and the total number of values to read on that dimension. m must
be less than or equal to the number of dimensions of the variable.
If m is less than the total number of dimensions, cdfread reads
every value from the unspecified dimensions ([0 1 n],
where n is the total number of elements in the
dimension. Note: Because the 'Slices' parameter describes how to process a single variable, it must be used in conjunction with the 'Variables' parameter. |
'ConvertEpochToDatenum' | A Boolean value that determines whether cdfread automatically converts CDF epoch data types to MATLAB^{®} serial date numbers. If set to false (the default), cdfread wraps epoch values in MATLAB cdfepoch objects. Note: For better performance when reading large data sets, set this parameter to true. |
'CombineRecords' | A Boolean value that determines how cdfread returns
the CDF data sets read from the file. If set to false (the
default), cdfread stores the data in an m-by-n cell
array, where m is the number of records and n is
the number of variables requested. If set to true, cdfread combines
all records for a particular variable into one cell in the output
cell array. In this cell, cdfread stores scalar
data as a column array. cdfread extends the dimensionality
of nonscalar and string data. For example, instead of creating 1000
elements containing 20-by-30 arrays for each record, cdfread stores
all the records in one cell as a 1000-by-20-by-30 array Note: If you use the 'Records' parameter to specify which records to read, you cannot use the 'CombineRecords' parameter. Note: When using the 'Variable' parameter to read one variable, if the 'CombineRecords' parameter is true, cdfread returns the data as an M-by-N numeric or character array; it does not put the data into a cell array. |
Note: To improve performance when working with large data files, use the 'ConvertEpochToDatenum' and 'CombineRecords' options. |
Note: To improve performance, turn off the file validation which the CDF library does by default when opening files. For more information, see cdflib.setValidate. |
Read all the data from a CDF file.
data = cdfread('example.cdf');
Read the data from the variable 'Time'.
data = cdfread('example.cdf', 'Variable', {'Time'});
Read the first value in the first dimension, the second value in the second dimension, the first and third values in the third dimension, and all values in the remaining dimension of the variable 'multidimensional'.
data = cdfread('example.cdf', ... 'Variable', {'multidimensional'}, ... 'Slices', [0 1 1; 1 1 1; 0 2 2]);
This is similar to reading the whole variable into data and then using matrix indexing, as in the following.
data{1}(1, 2, [1 3], :)
Collapse the records from a data set and convert CDF epoch data types to MATLAB serial date numbers.
data = cdfread('example.cdf', ... 'CombineRecords', true, ... 'ConvertEpochToDatenum', true);