Programming Previous page   Next Page

Using the MATLAB hdfread Function

To import data from an HDF or HDF-EOS file, you can use the hdfread function. The hdfread function provides a programmatic way to import data from an HDF4 file, in contrast to the interactive HDF Import Tool, described in Using the HDF Import Tool. The hdfread function hides many of the details that you need to know if you use the low-level HDF functions, described in Using the HDF4 Command-Line Interface.

To use the hdfread function to import data from an HDF4 file, you must know the name of the data set in the file that you want to read. To get this information, use the hdfinfo function. This section describes these high-level MATLAB HDF functions, including

To export data to an HDF4 file, you must use the low-level functions described in Exporting MATLAB Data to an HDF4 File.

Getting Information About an HDF4 File

To get information about the contents of an HDF4 file, use the hdfinfo function. The hdfinfo function returns a structure that contains information about the file and the data in the file.

This example returns information about a sample HDF4 file included with MATLAB:

To get information about the data sets stored in the file, look at the SDS field.

Importing Data from a HDF4 File

To import data into the MATLAB workspace from an HDF4 file, use the hdfread function. To use this function, you must specify the data set that you want to read. Use the hdfinfo function to get this information.

The following example illustrates this process. This example also illustrates how to import a subset of the data in a data set. See Reading a Subset of the Data in a Data Set for more information.

  1. Determine the names of data sets in the HDF4 file, using the hdfinfo function.
  1. To determine the names and other information about the data sets in the file, look at the contents of the SDS field. The Name field in the SDS structure gives the name of the data set.

  1. Read the data set from the HDF4 file, using the hdfread function. Specify the name of the data set as a parameter to the function. Note that the data set name is case sensitive. This example returns a 16-by-5 array:

Reading a Subset of the Data in a Data Set.   To read a subset of a data set, you can use the optional 'index' parameter. The value of the index parameter is a cell array of three vectors that specify the location in the data set to start reading, the skip interval (e.g., read every other data item), and the amount of data to read (e.g., the length along each dimension). In HDF4 terminology, these parameters are called the start, stride, and edge values.

For example, this code


Previous page  Using the HDF4 Import Tool Subsetting Options Using the HDF4 Command-Line Interface Next page

© 1994-2005 The MathWorks, Inc.