Main Content

Dataspace (H5S)

Dimensionality of dataset

Description

Use the MATLAB® HDF5 dataspace interface, H5S, to create and handle dataspaces, and access information about them.

An HDF5 dataspace defines the size and shape of the dataset or attribute raw data, and must be defined when the dataset or attribute is created.

Functions

H5S.copy

Create copy of dataspace

output = H5S.copy(spaceID) creates an identical copy of the dataspace identified by spaceID.

H5S.create

Create new dataspace

spaceID = H5S.create(spacetype) creates a new dataspace identifier of type spacetype.

 Details

H5S.close

Close dataspace

H5S.close(spaceID) releases and terminates access to the dataspace spaceID.

H5S.create_simple

Create new simple dataspace

spaceID = H5S.create_simple(rank,dims,maxdims) creates a new simple dataspace and opens it for access.

 Details

H5S.extent_copy

Copy extent from source to destination dataspace

H5S.extent_copy(destID,srcID) copies the extent from a source dataspace srcID to the destination dataspace destID.

H5S.get_regular_hyperslab

Retrieve a regular hyperslab selection (since R2021b)

[start,stride,count,block] = H5S.get_regular_hyperslab(spaceID) retrieves a regular hyperslab selection.

 Details

H5S.is_simple

Determine if dataspace is simple

output = H5S.is_simple(spaceID) returns a positive value if the dataspace specified by spaceID is a simple dataspace, zero if it is not, and a negative value to indicate failure.

H5S.is_regular_hyperslab

Determine whether a hyperslab selection is regular (since R2021b)

output = H5S.is_regular_hyperslab(spaceID) returns a value of 1 if the hyperslab selection associated with spaceID is regular, and 0 if it is not. A value of -1 indicates an error.

H5S.offset_simple

Set offset of simple dataspace

H5S.offset_simple(spaceID,offset) specifies the offset of the simple dataspace specified by spaceID. This function allows the same shaped selection to be moved to different locations within a dataspace without requiring it to be redefined.

 Details

H5S.select_all

Select entire extent of dataspace

H5S.select_all(spaceID) selects the entire extent of the dataspace specified by spaceID.

H5S.select_elements

Specify coordinates to include in selection

H5S.select_elements(spaceID,op,coord) selects array elements to include in the selection for the dataspace specified by spaceID.

 Details

H5S.select_hyperslab

Select hyperslab region

H5S.select_hyperslab(spaceID,op,start,stride,count,block) selects a hyperslab region to add to the current selected region for the dataspace specified by spaceID.

 Details

H5S.select_none

Reset selection region to include no elements

H5S.select_none(spaceID) resets the selection region for the dataspace spaceID to include no elements.

H5S.select_valid

Determine validity of selection

tf = H5S.select_valid(spaceID) returns a positive value if the selection of the dataspace specified by spaceID is within the extent of that dataspace, and 0 if it is not. A negative value indicates an error.

H5S.set_extent_none

Remove extent from dataspace

H5S.set_extent_none(spaceID) removes the extent from a dataspace and sets the type to H5S_NO_CLASS.

H5S.set_extent_simple

Set size of dataspace

H5S.set_extent_simple(spaceID,rank,dims,maxdims) sets the size of the dataspace identified by spaceID.

 Details

H5S.get_select_bounds

Bounding box of dataspace selection

[start,finish] = H5S.get_select_bounds(spaceID) returns the coordinates of the bounding box containing the current selection.

 Details

H5S.get_select_elem_npoints

Number of element points in selection

numpoints = H5S.get_select_elem_npoints(spaceID) returns the number of element points in the current dataspace selection.

H5S.get_select_elem_pointlist

Element points in dataspace selection

points = H5S.get_select_elem_pointlist(spaceID,start,numpoints) returns the list of element points in the current dataspace selection.

 Details

H5S.get_select_hyper_blocklist

List of hyperslab blocks

blocklist = H5S.get_select_hyper_blocklist(spaceID,start,numblocks) returns a list of the hyperslab blocks currently selected.

 Details

H5S.get_select_hyper_nblocks

Number of hyperslab blocks

numblocks = H5S.get_select_hyper_nblocks(spaceID) returns the number of hyperslab blocks in the current dataspace selection.

H5S.get_select_npoints

Number of elements in dataspace selection

numpoints = H5S.get_select_npoints(spaceID) returns the number of elements in the current dataspace selection.

H5S.get_select_type

Type of dataspace selection

selection = H5S.get_select_type(spaceID) returns the selection type.

 Details

H5S.get_simple_extent_dims

Return dataspace size and maximum size

[numdims,dimsize,maxdims] = H5S.get_simple_extent_dims(spaceID) returns the number of dimensions in the dataspace, the size of each dimension, and the maximum size of each dimension.

 Details

H5S.get_simple_extent_ndims

Return dataspace rank

output = H5S.get_simple_extent_ndims(spaceID) returns the dimensionality, also known as the rank, of a dataspace.

H5S.get_simple_extent_npoints

Number of elements in dataspace

output = H5S.get_simple_extent_npoints(spaceID) returns the number of elements in the dataspace specified by spaceID.

H5S.get_simple_extent_type

Return dataspace class

spacetype = H5S.get_simple_extent_type(spaceID) returns the class of the dataspace specified by spaceID.

Examples

expand all

Use the H5S.get_simple_extent_dims function to get information about the dimensions of the dataspace.

fid = H5F.open('example.h5');
dset_id = H5D.open(fid,'/g2/dset2.2');
space_id = H5D.get_space(dset_id);
[ndims,h5_dims] = H5S.get_simple_extent_dims(space_id);
matlab_dims = fliplr(h5_dims);

Select a hyperslab with the H5S.select_hyperslab function, and use the H5S.get_select_bounds function to get the coordinates of the selection within the dataspace space_id.

Create a new simple dataspace and select the hyperslab.

dims = [100 200];
h5_dims = fliplr(dims);
space_id = H5S.create_simple(2,h5_dims,h5_dims);
start = fliplr([10 20]); block = fliplr([20 30]);
H5S.select_hyperslab(space_id,'H5S_SELECT_SET',start,[],[],block);
offset = fliplr([3 5]);
H5S.offset_simple(space_id,offset)

Query the bounding box of the current selection.

[start,finish] = H5S.get_select_bounds(space_id);
start = fliplr(start);
finish = fliplr(finish);

Select the corner points of a dataspace. In this case, h5_coord should have size 2x4.

dims = [100 200];
h5_dims = fliplr(dims);
space_id = H5S.create_simple(2,h5_dims,h5_dims);
coords = [0 0; 0 199; 99 0; 99 199];
h5_coords = fliplr(coords);
h5_coords = h5_coords';
H5S.select_elements(space_id,'H5S_SELECT_SET',h5_coords);

Use the H5S.set_extent_simple function to set the dimensions of the dataspace.

space_id = H5S.create('H5S_SIMPLE');
dims = [100 200];
h5_dims = fliplr(dims);
maxdims = [100 H5ML.get_constant_value('H5S_UNLIMITED')];
h5_maxdims = fliplr(maxdims);
H5S.set_extent_simple(space_id,2,h5_dims, h5_maxdims);
Introduced before R2006a