23.06.2015 Views

MATLAB Programming

MATLAB Programming

MATLAB Programming

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Hierarchical Data Format (HDF5) Files<br />

Note Because HDF5 stores data in row-major order and <strong>MATLAB</strong><br />

accesses data in column-major order, you should permute your data before<br />

writing it to the file.<br />

data_perm = permute(testdata,[3 2 1]);<br />

H5D.write(datasetID,'H5ML_DEFAULT','H5S_ALL','H5S_ALL', ...<br />

'H5P_DEFAULT',data_perm);<br />

5 Close the data set, data space, data type, and file objects. If used inside a<br />

<strong>MATLAB</strong> function, these identifiers are closed automatically when they<br />

go out of scope.<br />

H5D.close(datasetID);<br />

H5S.close(dataspaceID);<br />

H5T.close(datatypeID);<br />

H5F.close(fileID);<br />

6 To read the data set you wrote to the file, you must open the file. In HDF5,<br />

you use the H5Fopen routinetoopenanHDF5file,specifyingthenameof<br />

the file, the access mode, and a property list as arguments. The example<br />

uses the corresponding <strong>MATLAB</strong> function, H5F.open, openingthefilefor<br />

read-only access.<br />

fileID = H5F.open(filename,'H5F_ACC_RDONLY','H5P_DEFAULT');<br />

7 After opening the file, you must open the data set. In HDF5, you use the<br />

H5Dopen function to open a data set. The example uses the corresponding<br />

<strong>MATLAB</strong> function, H5D.open, specifying as arguments the file ID and the<br />

name of the data set, defined earlier in the example.<br />

datasetID = H5D.open(fileID, dsetname);<br />

8 After opening the data set, you can read the data into the <strong>MATLAB</strong><br />

workspace. In HDF5, you use the H5Dread function to read an HDF5<br />

file. The example uses the corresponding <strong>MATLAB</strong> function, H5D.read,<br />

specifying as arguments the data set ID, the memory data type ID, the<br />

memory space ID, the data space ID, and the transfer property list ID.<br />

7-33

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

Saved successfully!

Ooh no, something went wrong!