Main Content

hdf5read

(Not recommended) Read HDF5 file

hdf5read is not recommended. Use h5read instead.

Description

data = hdf5read(filename,ds) reads all the data from the dataset ds contained in the HDF5 file filename.

attr = hdf5read(filename,attrname) reads all the metadata of an attribute attrname contained in the HDF5 file filename.

data = hdf5read(info) reads all of the data in the dataset specified in the structure info. The info structure is the output returned by hdf5info.

[data,attr] = hdf5read(___,Name,Value) specifies optional name-value arguments, in addition to any of the input arguments in the previous syntaxes.

Input Arguments

collapse all

File name, specified as a character vector or string scalar containing the name of an existing HDF5 file.

Depending on the location of your file, filename can take on one of these forms.

Location

Form

Current folder

Specify the name of the file in filename.

Example: 'myFile.h5'

Other folders

If the file is not in the current folder or in a folder on the MATLAB® path, then specify the full or relative path name in filename.

Example: 'C:\myFolder\myFile.h5'

Example: 'myFolder\myFile.h5'

Dataset name, specified as a character vector or string scalar containing the full path name of the dataset in the HDF5 file.

Attribute name, specified as a character vector or string scalar containing the full path name of an attribute belonging to a group or dataset.

Input data, specified as a structure array. The info structure is the output returned by the hdf5info function.

Name-Value Arguments

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Before R2021a, use commas to separate each name and value, and enclose Name in quotes.

Example: 'ReadAttributes',true reads all of the associated attribute information contained within that dataset.

Indicator for reading attributes, specified as the comma-separated pair consisting of 'ReadAttributes' and either true or false.

If you specify true, then hdf5read reads all of the associated attribute information contained within that dataset. The default value of 'ReadAttributes' is false, which omits attribute information when reading data from an HDF5 file.

Compatibility with MATLAB 7.1 and earlier, specified as the comma-separated pair consisting of 'V71Dimensions' and either true or false. If you specify true, then hdf5read permutes the first two dimensions of the dataset, making the dimension order of the output dataset consistent with previous versions of hdf5read (MATLAB 7.1 [R14SP3] and earlier). This behavior was intended to account for the difference in how HDF5 and MATLAB express array dimensions.

The default value of 'V71Dimensions' is false, which does not change the order of the output data dimensions.

HDF5 describes dataset dimensions in row-major order, while MATLAB stores data in column-major order. However, permuting these dimensions may not correctly reflect the intent of the data and may invalidate metadata. When you specify 'V71Dimensions' as false, the data dimensions correctly reflect the data ordering as it is written in the file; each dimension in the output variable matches the same dimension in the file.

Example: 'V71Dimensions',true

Output Arguments

collapse all

Output data, returned by hdf5read as a multidimensional array.

Examples

collapse all

Use hdf5info to get information about an HDF5 file and then use hdf5read to read a dataset, using the information structure (hinfo) returned by hdf5info to specify the dataset.

hinfo = hdf5info('example.h5');
dset = hdf5read(hinfo.GroupHierarchy.Groups(2).Datasets(1));

Tips

  • hdf5read performs best when reading numeric datasets. If you need to read string, compound, or variable length datasets, it is strongly recommended that you use the low-level HDF5 interface function, H5D.read. To read a subset of a dataset, use the h5read function or the MATLAB HDF5 low-level interface.

  • hdf5read maps HDF5 datatypes to native MATLAB data types, whenever possible. If it cannot represent the data using MATLAB data types, hdf5read uses one of the HDF5 datatype objects. For example, if an HDF5 file contains a dataset made up of an enumerated datatype, hdf5read uses the hdf5.h5enum object to represent the data in the MATLAB workspace. The hdf5.h5enum object has data members that store the enumerations (names), their corresponding values, and the enumerated data.

Version History

Introduced before R2006a

See Also

| |