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.

7 Working with Scientific Data Formats<br />

c<br />

Create the data set. In HDF5, you use the H5Dcreate routine to create<br />

a data set. The example uses the corresponding <strong>MATLAB</strong> function,<br />

H5D.create, specifying the file ID, the name you want to assign to<br />

the data set, data type ID, the data space ID, and a data set creation<br />

property list ID as arguments. The example uses the defaults for the<br />

property lists. The function returns a data set ID.<br />

dsetname = 'my_dataset';<br />

datasetID = H5D.create(fileID,dsetname,datatypeID,dataspaceID,'H5P_DEFAULT');<br />

Note To write a large data set, you must use the chunking capability<br />

of the HDF5 library. To do this, create a property list and use the<br />

H5P.set_chunk function to set the chunk size in the property list. In the<br />

following example, the dimensions of the data set are dims = [2^16<br />

2^16] and the chunk size is 1024-by-1024. You then pass the property<br />

list as the last argument to the data set creation function, H5D.create,<br />

instead of using the H5P_DEFAULT value.<br />

plistID = H5P.create('H5P_DATASET_CREATE'); % create property list<br />

chunk_size = min([1024 1024], dims); % define chunk size<br />

H5P.set_chunk(plistID, chunk_size); % set chunk size in property list<br />

datasetID = H5D.create(fileID, dsetname, datatypeID, dataspaceID, plistID);<br />

4 Write the data to the data set. In HDF5, you use the H5Dwrite routine to<br />

writedatatoadataset. Theexampleusesthecorresponding<strong>MATLAB</strong><br />

function, H5D.write, specifying as arguments the data set ID, the memory<br />

data type ID, the memory space ID, the data space ID, the transfer property<br />

listIDandthenameofthe<strong>MATLAB</strong>variabletobewrittentothedataset.<br />

You can use the memory data type to specify the data type used to represent<br />

the data in the file. The example uses the constant 'H5ML_DEFAULT' which<br />

lets the <strong>MATLAB</strong> function do an automatic mapping to HDF5 data types.<br />

The memory data space ID and the data set’s data space ID specify to write<br />

subsets of the data set to the file. The example uses the constant 'H5S_ALL'<br />

to write all the data to the file and uses the default property list.<br />

7-32

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

Saved successfully!

Ooh no, something went wrong!