h5writeatt
Write HDF5 attribute
Description
h5writeatt(
writes filename
,loc
,attr
,val
,'TextEncoding'
,encoding
)attr
to the specified location in the HDF5 file using the
specified encoding. 'UTF-8'
is the default setting for
'TextEncoding'
, while 'system'
uses the
system encoding to represent characters. It is usually unnecessary to specify
'system'
as the encoding.
Examples
Write Attribute to Root Group
Write an attribute to the root group of examplefile.h5
whose value is the current time.
date = datestr(now); h5writeatt('examplefile.h5','/','creation_date', date);
Read the attribute from the root group of the HDF5 file.
val1 = h5readatt('examplefile.h5','/','creation_date')
val1 = '03-Mar-2023 06:27:42'
Write Attribute to Dataset
Create an array of doubles and write it to the dataset /g4/world
.
attData = [0 1 2 3]; h5writeatt('examplefile.h5','/g4/world','val2',attData);
Display the dataset metadata. The attribute val2
is listed one of the attributes belonging to the dataset.
h5disp('examplefile.h5','/g4/world');
HDF5 examplefile.h5 Dataset 'world' Size: 36x19 MaxSize: 36x19 Datatype: H5T_IEEE_F64LE (double) ChunkSize: [] Filters: none FillValue: 0.000000 Attributes: 'val2': 0.000000 1.000000 2.000000 3.000000
Input Arguments
filename
— File name
character vector | string scalar
File name, specified as a character vector or string scalar containing the name of an existing HDF5 file.
Depending on the location you are writing to, filename
can take on one of these forms.
Location | Form | ||||||
---|---|---|---|---|---|---|---|
Current folder | To write to the current folder, specify the
name of the file in
Example:
| ||||||
Other folders | To write to a folder different from the current
folder, specify the full or relative path name in
Example:
Example:
| ||||||
Remote Location | To write to a remote location,
Based on your
remote location,
For more information, see Work with Remote Data. Example:
|
loc
— Location in file
character vector | string scalar
Location in file, specified as a character vector or string scalar containing the full path name of an existing group or dataset to which you want to associate the attribute.
attr
— Name of attribute
character vector | string scalar
Name of attribute, specified as a character vector or string scalar
containing the name of an attribute belonging to a group or dataset. 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 val
,
h5writeatt
deletes the attribute and recreates it.
String attributes are created with a scalar dataspace, which is a single,
zero-dimensional data point.
val
— Value of attribute
character vector | string array | numeric value
Value of attribute to be written, specified as a character vector, string scalar, or numeric value.
encoding
— Text Encoding
'UTF-8'
(default) | 'system'
Text encoding, specified as the comma-separated pair consisting of
'TextEncoding'
and one of these values:
'UTF-8'
— Represents characters using UTF-8 encoding.'system'
— Represents characters as bytes using the system encoding (not recommended).
Limitations
h5writeatt
does not support writing to files stored remotely in HDFS™.
Version History
Introduced in R2011aR2020b: Write attributes to HDF5 files at a remote location
You can write attributes to HDF5 files in remote locations, such as Amazon S3, Windows Azure Blob Storage, and HDFS.
R2020b: Write attributes to HDF5 files with Unicode names
You can write attributes to HDF5 files whose names are encoded as Unicode characters.
R2020a: UTF-8 character encoding is the default setting
UTF-8 is now the default character encoding for h5writeatt
so
that all Unicode code points can be represented in HDF5 files. Previously, the
default encoding was ASCII.
Open Example
You have a modified version of this example. Do you want to open this example with your edits?
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)