This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.


Read data from HDF5 data set


data = h5read(filename,datasetname)
data = h5read(filename,datasetname,start,count)
data = h5read(filename,datasetname,start,count,stride)


data = h5read(filename,datasetname) retrieves all of the data from the HDF5 data set datasetname in the file filename.

data = h5read(filename,datasetname,start,count) reads a subset of data from the data set datasetname. start is the one-based index of the first element to be read. count defines how many elements to read along each dimension. If a particular element of count is Inf, h5read reads data until the end of the corresponding dimension.

data = h5read(filename,datasetname,start,count,stride) reads a subset of data, where stride specifies the interelement spacing along each data set extent.

Input Arguments


Character vector or string scalar specifying the name of an HDF5 file.


Character vector or string scalar specifying the name of a data set in an HDF5 file.


Numeric index value specifying the place to start reading data in the dataset in an HDF5 file. Indices are 1-based.


Numeric value specifying the amount of data to read.


Numeric value specifying the intervalue spacing during the read operation. For example, a spacing of 2 indicates reading every other value.

Output Arguments


Data read from the data set.


collapse all

Read an entire data set from the sample file, example.h5.

HDF5 example.h5 
Dataset 'lat' 
    Size:  19
    MaxSize:  19
    Datatype:   H5T_IEEE_F64LE (double)
    ChunkSize:  []
    Filters:  none
    FillValue:  0.000000
        'units':  'degrees_north'
        'NAME':  'lat'
data = h5read('example.h5','/g4/lat')
data = 19×1


Read the first 5-by-3 subset of a data set.

HDF5 example.h5 
Dataset 'world' 
    Size:  36x19
    MaxSize:  36x19
    Datatype:   H5T_IEEE_F64LE (double)
    ChunkSize:  []
    Filters:  none
    FillValue:  0.000000
data = h5read('example.h5','/g4/world',[1 1],[5 3])
data = 5×3

     0     0     0
     0     0     0
     0     0     0
     0     0     0
     0     0     0

Read a data set of references to other data sets.

HDF5 example.h5 
Dataset 'reference' 
    Size:  2
    MaxSize:  2
    Datatype:   H5T_REFERENCE
    ChunkSize:  []
    Filters:  none
    FillValue:  H5T_REFERENCE
data = h5read('example.h5','/g3/reference')
data = 2x1 cell array
    {2x1 int32 }
    {2x1 single}

Introduced in R2011a