h5writeatt

Write HDF5 attribute

Syntax

h5writeatt(filename,location,attname,attvalue)

Description

h5writeatt(filename,location,attname,attvalue) writes the attribute named attname with the value attvalue to the HDF5 file filename. The parent object location can be either a group or variable. location is the complete path name of the group or variable to which you want to associate the attribute.

Input Arguments

filename

Text string specifying the name of an HDF5 file.

location

Text string specifying the full path identifying a group or variable in an HDF5 file.

attname

Text string specifying the name of an attribute in an HDF5 file. If the attribute does not exist, h5writeatt creates the attribute with the name specified.

If the specified attribute already exists but does not have a datatype or dataspace consistent with attvalue, h5writeatt deletes the attribute and recreates it. String attributes are created with a scalar dataspace.

attvalue

Value to be written to the attribute in an HDF5 file.

Examples

Create a root group attribute whose value is the current time.

srcFile = fullfile(matlabroot,'toolbox','matlab','demos','example.h5');
copyfile(srcFile,'myfile.h5');
fileattrib('myfile.h5','+w');
h5writeatt('myfile.h5','/','creation_date',datestr(now));

Create a double-precision data set attribute.

srcFile = fullfile(matlabroot,'toolbox','matlab','demos','example.h5');
copyfile(srcFile,'myfile.h5');
fileattrib('myfile.h5','+w');
attData = [0 1 2 3];
h5writeatt('myfile.h5','/g4/world','attr',attData);
h5disp('myfile.h5','/g4/world');
Was this topic helpful?