Main Content


(Not recommended) Read HDF5 file



hdf5read is not recommended. Use h5read instead.


data = hdf5read(filename,datasetname)
attr = hdf5read(filename,attributename)
[data, attr] = hdf5read(...,'ReadAttributes',BOOL)
data = hdf5read(hinfo)
[...] = hdf5read(..., 'V71Dimensions', BOOL)


data = hdf5read(filename,datasetname) reads all the data in the data set datasetname that is stored in the HDF5 file filename and returns it in the variable data. To determine the names of data sets in an HDF5 file, use the hdf5info function.

The return value, data, is a multidimensional array. hdf5read maps HDF5 data types to native MATLAB® data types, whenever possible. If it cannot represent the data using MATLAB data types, hdf5read uses one of the HDF5 data type objects. For example, if an HDF5 file contains a data set made up of an enumerated data type, 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.


hdf5read performs best when reading numeric datasets. If you need to read string, compound, or variable length datasets, MathWorks strongly recommends that you use the low-level HDF5 interface function, To read a subset of a dataset, you must use the low-level interface.

attr = hdf5read(filename,attributename) reads all the metadata in the attribute attributename, stored in the HDF5 file filename, and returns it in the variable attr. To determine the names of attributes in an HDF5 file, use the hdf5info function.

[data, attr] = hdf5read(...,'ReadAttributes',BOOL) reads all the data, as well as all of the associated attribute information contained within that data set. By default, BOOL is false.

data = hdf5read(hinfo) reads all of the data in the data set specified in the structure hinfo and returns it in the variable data. The hinfo structure is extracted from the output returned by hdf5info, which specifies an HDF5 file and a specific data set.

[...] = hdf5read(..., 'V71Dimensions', BOOL) specifies whether to change the majority of data sets read from the file. If BOOL is true, hdf5read permutes the first two dimensions of the data set, as it did in previous releases (MATLAB 7.1 [R14SP3] and earlier). This behavior was intended to account for the difference in how HDF5 and MATLAB express array dimensions. HDF5 describes data set dimensions in row-major order; 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 BOOL is false (the default), 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.


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

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