h5writeatt
Write attribute to HDF5 file
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 = '05-Sep-2024 15:14:24'
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
— Filename
string scalar | character vector
Filename of an existing HDF5 file, specified as a string scalar or character vector.
Depending on the location of your file, filename
can take one of
these forms.
Location | Form | ||||||
---|---|---|---|---|---|---|---|
Current folder | Specify the name of the file in
Example:
| ||||||
Other folders | If the file is not in the current folder or in a folder on
the MATLAB® path, then specify the full or relative path in
Example:
Example:
| ||||||
Remote location | If the file is stored at a remote location, then
Based on your remote location,
For more information, see Work with Remote Data. Example:
|
If your file consists of several physical files using the Family driver, specify
filename
using a format specifier. For example, to use the Family driver with the two filesfamily0.h5
andfamily1.h5
, specifyfilename
as"family%d.h5"
.If your file consists of several physical files using the Multi driver or the Split driver, specify
filename
as the leading prefix of the names of the physical files. For example, to use the Multi driver with the six filesmulti-b.h5
,multi-g.h5
,multi-l.h5
,multi-o.h5
,multi-r.h5
, andmulti-s.h5
, specifyfilename
as"multi"
.
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.
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)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)