Main Content

h5readatt

Read attribute from HDF5 file

Description

attval = h5readatt(filename,loc,attr) retrieves the value of the specified attribute from the specified location in an HDF5 file.

example

Examples

collapse all

Read the attribute attr2 from the root group of the HDF5 file example.h5.

val = h5readatt('example.h5','/','attr2')
val = 2x2 int32 matrix

   0   2
   1   3

Read the attribute units from the dataset lon in the HDF5 file example.h5.

val = h5readatt('example.h5','/g4/lon','units')
val = 
'degrees_east'

Input Arguments

collapse all

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 filename.

Example: "myFile.h5"

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 filename.

Example: "C:\myFolder\myFile.h5"

Example: "myFolder\myFile.h5"

Uniform resource locator (URL) (since R2024b)

If the file is located by an internet URL, then filename must contain the protocol type, such as http://. For more information, see Work with Remote Data.

Example: "http://my_hostname/my_path/my_file.h5"

Remote location

If the file is stored at a remote location, then filename must contain the full path of the file specified as a uniform resource locator (URL) of the form:

scheme_name://path_to_file/filename

Based on your remote location, scheme_name can be one of the values in this table.

Remote Locationscheme_name
Amazon S3™s3
Windows Azure® Blob Storagewasb, wasbs
HDFS™hdfs

For more information, see Work with Remote Data.

Example: "s3://myBucket/myFolder/myFile.h5"

  • 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 files family0.h5 and family1.h5, specify filename 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 files multi-b.h5, multi-g.h5, multi-l.h5, multi-o.h5, multi-r.h5, and multi-s.h5, specify filename as "multi".

Location in the file, specified as a character vector or string scalar containing the full path of an existing group or dataset to which the attribute belongs. To read an attribute from the root group of the file, specify '/' as the location.

Attribute name, specified as a character vector or string scalar containing the name of an attribute belonging to a group or dataset.

Limitations

  • MATLAB does not support internet URLs that require authentication.

  • MATLAB Online™ supports internet URLs associated with Microsoft® OneDrive™ files and folders, while the installed version of MATLAB supports only local OneDrive files.

  • The h5readatt function issues an error for attributes and datasets that fail file integrity checks. To read attributes in such situations, use the H5P.set_relax_file_integrity_checks function and the low-level HDF5 interface. (since R2024b)

Version History

Introduced in R2011a

expand all