Programming |
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.
Note You can also use the HDF Import Tool to get information about the contents of an HDF4 file. See Using the HDF Import Tool for more information. |
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.
SDS
field. The Name
field in the SDS structure gives the name of the data set.
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.
[3 3]
).
]
).
[10 2]
).
Using the HDF4 Import Tool Subsetting Options | Using the HDF4 Command-Line Interface |
© 1994-2005 The MathWorks, Inc.