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.

7 Working with Scientific Data Formats<br />

Note SDgetinfo returns dimension values in row-major order, the ordering<br />

used by HDF4. Because <strong>MATLAB</strong> stores data in column-major order, you<br />

must specify the dimensions in column-major order, that is, [columns,rows].<br />

In addition, you must use zero-based indexing in these arguments.<br />

For example, to read the entire contents of a data set, use this code:<br />

[ds_name, ds_ndims, ds_dims, ds_type, ds_atts, stat] =<br />

hdfsd('getinfo',sds_id);<br />

ds_start = zeros(1,ds_ndims); % Creates the vector [0 0]<br />

ds_stride = [];<br />

ds_edges = ds_dims;<br />

[ds_data, status] =<br />

hdfsd('readdata',sds_id,ds_start,ds_stride,ds_edges);<br />

disp(ds_data)<br />

1 2 3 4 5<br />

6 7 8 9 10<br />

11 12 13 14 15<br />

To read less than the entire data set, use the start, stride, and edges vectors<br />

to specify where you want to start reading data and how much data you want<br />

to read. For example, this code reads the entire second row of the sample<br />

data set:<br />

ds_start = [0 1]; % Start reading at the first column, second row<br />

ds_stride = []; % Read each element<br />

ds_edges = [5 1]; % Read a 1-by-5 vector of data<br />

[ds_data, status] =<br />

hdfsd('readdata',sds_id,ds_start,ds_stride,ds_edges);<br />

Step 7: Closing the HDF4 Data Set. After writing data to a data set in an<br />

HDF4 file, you must close access to the data set. In the HDF4 SD API, you<br />

use the SDendaccess routine to close a data set. In <strong>MATLAB</strong>, use the hdfsd<br />

function, specifying as arguments:<br />

7-62

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

Saved successfully!

Ooh no, something went wrong!