Documentation

This is machine translation

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

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

h5writeatt

Write HDF5 attribute

Syntax

h5writeatt(filename,location,attname,attvalue)
h5writeatt(filename,location,attname,attvalue,'TextEncoding',encoding)

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.

h5writeatt(filename,location,attname,attvalue,'TextEncoding',encoding) additionally specifies the text encoding to use when writing the attribute name or any attribute values that are of the text data type.

Input Arguments

filename

Character vector specifying the name of an HDF5 file.

location

Character vector specifying the full path identifying a group or variable in an HDF5 file.

attname

Character vector 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.

encoding

Character encoding, specified as 'system' or 'UTF-8'.

  • 'system' — Use the system default encoding for the attribute name and any attribute values that are of the text data type.

  • 'UTF-8' — Use UTF-8 encoding for the attribute name and any attribute values that are of the text data type.

Default: 'system'

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');

Introduced in R2011a

Was this topic helpful?