23.06.2015 Views

MATLAB Programming

MATLAB Programming

MATLAB Programming

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Hierarchical Data Format (HDF5) Files<br />

• Name of an existing data set or attribute,orthenameyouwanttoassign<br />

to a new data set or attribute. To learn how to determine the name of data<br />

sets in an existing HDF5 file, see “Determining the Contents of an HDF5<br />

File” on page 7-12.<br />

• Data or metadata you want to write to the file. hdf5write converts<br />

<strong>MATLAB</strong> data types to the appropriate HDF5 data type automatically.<br />

For nonatomic data types, you can also create HDF5 objects to represent<br />

the data.<br />

This example creates a 5-by-5 array of uint8 values and then writes the<br />

array to an HDF5 file. By default, hdf5write overwrites the file, if it already<br />

exists. The example specifies an hdf5write mode option to append data to<br />

existing file.<br />

1 Create a <strong>MATLAB</strong> variable in the workspace. This example creates a<br />

5-by-5 array of uint8 values.<br />

testdata = uint8(magic(5))<br />

2 Write the data to an HDF5 file. As arguments to hdf5read, theexample<br />

specifiesthenameyouwanttoassigntotheHDF5file,thenameyouwant<br />

to assign to the data set, and the <strong>MATLAB</strong> variable.<br />

hdf5write('myfile.h5', '/dataset1', testdata)<br />

To add data to an existing file, you must use the 'writemode' option,<br />

specifying the'append' value. The file must already exist and it cannot<br />

already contain a data set with the same name<br />

hdf5write('myfile.h5', '/dataset12', testdata,'writemode','append')<br />

If you are writing simple data sets, such as scalars, strings, or a simple<br />

compound data types, you can just pass the data directly to hdf5write; this<br />

function automatically maps the <strong>MATLAB</strong> data types to appropriate HDF5<br />

data types. However, if your data is a complex data set, you might need to<br />

use one of the predefined <strong>MATLAB</strong> HDF5 objects to pass the data to the<br />

hdf5write function. The HDF5 objects are designed for situations where the<br />

mapping between <strong>MATLAB</strong> and HDF5 types is ambiguous.<br />

For example, when passed a cell array of strings, the hdf5write function<br />

writes a data set made up of strings, not a data set of arrays containing<br />

7-17

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!