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 />

attr_idx = 0;<br />

[attr, status] = hdfsd('readattr', sd_id, attr_idx);<br />

attr =<br />

my global attribute<br />

Step 4: Selecting the Data Sets to Import. To select a data set, use<br />

the SD API routine SDselect. In<strong>MATLAB</strong>,youusethe hdfsd function,<br />

specifying as arguments:<br />

• Name of the SD API routine, select in this case<br />

• HDF4 SD file identifier (sd_id) returnedbySDstart<br />

If SDselect finds the specified data set in the file, it returns an HDF4 SD<br />

data set identifier, called sds_id intheexample. Ifitcannotfindthedata<br />

set, it returns -1.<br />

Note Do not confuse HDF4 SD file identifiers, named sd_id in the examples,<br />

with HDF4 SD data set identifiers, named sds_id in the examples.<br />

sds_id = hdfsd('select',sd_id,1)<br />

Step 5: Getting Information About a Data Set. To read a data set, you<br />

must get information about the data set, such as its name, size, and data<br />

type. In the HDF4 SD API, you use the SDgetinfo routine to gather this<br />

information. In <strong>MATLAB</strong>, use the hdfsd function, specifying as arguments:<br />

• Name of the SD API routine, getinfo in this case<br />

• HDF4 SD data set identifier (sds_id) returnedbySDselect<br />

This code retrieves information about the data set identified by sds_id:<br />

[dsname, dsndims, dsdims, dstype, dsatts, stat] =<br />

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

dsname =<br />

A<br />

7-60

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

Saved successfully!

Ooh no, something went wrong!