Note: This page has been translated by MathWorks. Please click here

To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

Read data from Common Data Format (CDF) file

`data = cdfread(`

* filename*)

data = cdfread(

`filename`

`param1`

`val1`

[data, info] = cdfread(

`filename`

`data = cdfread(`

reads
all the data from the Common Data Format (CDF) file specified by the
character vector * filename*)

`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.Because `cdfread`

creates temporary files,
the current working directory must be writeable.

`data = cdfread(`

reads data from the file, where * filename*,

`param1`

`val1`

`param1`

, `param2`

,
and so on, can be any of the parameters listed in the following table.`[data, info] = cdfread(`

returns details about the CDF file in the * filename*,
...)

`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 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 arrayNote: If you use the `'Records'` parameter to specify which
records to read, you cannot use the `'CombineRecords'` parameter.Note: When using the |

To improve performance when working with large data files, use
the `'ConvertEpochToDatenum'`

and `'CombineRecords'`

options.

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);

The

`cdfread`

function does not support non-ASCII encoded data. All the variable names, attributes names, variable values, and attribute values in the CDF file must have 7-bit ASCII encoding. Attempting to read non-ASCII encoded files results in errors or data with corrupted characters.

Was this topic helpful?