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.


Write to HDF5 data set




h5write(filename,datasetname,data) writes data to an entire data set, datasetname, in the HDF5 file, filename.

h5write(filename,datasetname,data,start,count) writes a subset of the data to a data set, datasetname, in the HDF5 file, filename. start is a one-based index value that specifies the first element to be written. count specifies the number of elements to write along each dimension. h5write extends an extendable data set along any unlimited dimensions, if necessary.

h5write(filename,datasetname,data,start,count,stride) writes a hyperslab of data, where stride specifies the inter-element spacing along each dimension.

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 the HDF5 file.


Data to be written to the HDF5 file. You can specify only non-sparse floating-point and integer data sets.


Numeric index value specifying where in the data set to start writing to the file.


Numeric value specifying how much data to write to the file.


Numeric value specifying the interelement spacing of data to write to the file.

Default: Vector of ones.


collapse all

Write random values to a data set named DS1.

h5create('myfile.h5','/DS1',[10 20])
mydata = rand(10,20);
h5write('myfile.h5', '/DS1', mydata)

Display the contents of the file.

HDF5 myfile.h5 
Group '/' 
    Dataset 'DS1' 
        Size:  10x20
        MaxSize:  10x20
        Datatype:   H5T_IEEE_F64LE (double)
        ChunkSize:  []
        Filters:  none
        FillValue:  0.000000

Write a hyperslab of data to the last 5-by-7 block of a data set.

h5create('myfile.h5','/DS2',[10 20])
mydata = rand(5,7);
h5write('myfile.h5','/DS2',mydata,[6 14],[5 7])
h5create('myfile.h5','/DS3',[20 Inf],'ChunkSize',[5 5]);
for j = 1:10
      data = j*ones(20,1);
      start = [1 j];
      count = [20 1];
HDF5 myfile.h5 
Group '/' 
    Dataset 'DS3' 
        Size:  20x10
        MaxSize:  20xInf
        Datatype:   H5T_IEEE_F64LE (double)
        ChunkSize:  5x5
        Filters:  none
        FillValue:  0.000000


  • h5write supports only floating point and integer data sets. To write to string data sets, you must use the H5D package.

More About

collapse all


A hyperslab is a collection of points in a data space. The points can be contiguous or form a regular pattern of points or blocks in a data space.

Introduced in R2011a