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 (HDF4) Files<br />

Once you create a data set, you cannot change its name, data type, or<br />

dimensions.<br />

For example, to create a data set in which you can write the following<br />

<strong>MATLAB</strong> 3-by-5 array of doubles,<br />

A = [ 1 2 3 4 5 ; 6 7 8 9 10 ; 11 12 13 14 15 ];<br />

you could call hdfsd, specifying as arguments 'create' andavalidHDF<br />

file identifier, sd_id. In addition, set the values of the other arguments as<br />

in this code fragment:<br />

ds_name = 'A';<br />

ds_type = 'double';<br />

ds_rank = ndims(A);<br />

ds_dims = fliplr(size(A));<br />

sds_id = hdfsd('create',sd_id,ds_name,ds_type,ds_rank,ds_dims);<br />

If SDcreate can successfully create the data set, it returns an HDF4 SD data<br />

set identifier, (sds_id). Otherwise, SDcreate returns -1.<br />

In this example, note the following:<br />

• The data type you specify in ds_type must match the data type of the<br />

<strong>MATLAB</strong> array that you want to write to the data set. In the example, the<br />

array is of class double so the value of ds_type is set to 'double'. Ifyou<br />

wanted to use another data type, such as uint8, convertthe<strong>MATLAB</strong><br />

array to use this data type,<br />

A = uint8([ 1 2 3 4 5 ; 6 7 8 9 10 ; 11 12 13 14 15 ]);<br />

and specify the name of the <strong>MATLAB</strong> data type, uint8 in this case, in the<br />

ds_type argument.<br />

ds_type = 'uint8';<br />

• The code fragment reverses the order of the values in the dimensions<br />

argument (ds_dims). This processing is necessary because the <strong>MATLAB</strong><br />

size function returns the dimensions in column-major order and HDF4<br />

expects to receive dimensions in row-major order.<br />

7-65

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

Saved successfully!

Ooh no, something went wrong!