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

If it can write the data to the data set, SDwritedata returns 0; otherwise,<br />

it returns -1.<br />

Note SDwritedata queues write operations. To ensure that these queued<br />

write operations are executed, you must close the file, using the SDend routine.<br />

See “Step 6: Closing an HDF4 File” on page 7-70 for more information. As a<br />

convenience, <strong>MATLAB</strong> provides a function, MLcloseall, thatyoucanuseto<br />

close all open data sets and file identifiers with a single call. See “Using the<br />

<strong>MATLAB</strong> HDF4 Utility API” on page 7-70 for more information.<br />

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

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

to write.<br />

For example, the following code fragment uses SDwritedata to replace the<br />

values of the entire second row of the sample data set:<br />

1 2 3 4 5<br />

6 7 8 9 10<br />

11 12 13 14 15<br />

with the vector B:<br />

B = [ 9 9 9 9 9];<br />

In the example, the start vector specifies that you want to start the write<br />

operationinthefirstcolumnofthe second row. Note how HDF4 uses<br />

zero-based indexing and specifies the column dimension first. In <strong>MATLAB</strong>,<br />

you would specify this location as (2,1). The edges argument specifies the<br />

dimensions of the data to be written. Note that the size of the array of data<br />

to be written must match the edgespecification.<br />

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

ds_stride = []; % Write every element.<br />

ds_edges = [5 1]; % Each row is a 1-by-5 vector.<br />

stat = hdfsd('writedata',sds_id,ds_start,ds_stride,ds_edges,B);<br />

7-67

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

Saved successfully!

Ooh no, something went wrong!