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.

6 Data Import and Export<br />

m = memmapfile('records.dat', ...<br />

'Format', { ...<br />

'uint16' [300 8] 'x'; ...<br />

'double' [200 5] 'y' }, ...<br />

'Repeat', 1, 'Writable', true);<br />

m.Data.x = ones(300, 8, 'uint16');<br />

When Memory Is Mapped in Nonscalar Structure Format. When you<br />

map a file as a repeating sequence of multiple data types, you can use the<br />

following syntax to write matrix X to the file, providing that k is a scalar index:<br />

m.Data(k).field = X;<br />

To do this, the following conditions must be true:<br />

• Thefileismappedascontainingmultiple data types that can repeat,<br />

making m.Data a nonscalar structure.<br />

• k is a scalar index.<br />

• The class of X isthesameastheclassofm.Data(k).field.<br />

• The number of elements in X equals that of m.Data(k).field.<br />

This example maps a file as a matrix of type uint16 followed by a matrix of<br />

type double that repeat 20 times, and then uses the syntax shown above<br />

to write a matrix to the file.<br />

m = memmapfile('records.dat', ...<br />

'Format', { ...<br />

'uint16' [25 8] 'x'; ...<br />

'double' [15 5] 'y' }, ...<br />

'Repeat', 20, 'Writable', true);<br />

d = m.Data;<br />

d(12).x = ones(25,8,'uint16');<br />

You can write to specific elements of field x as shown here:<br />

d(12).x(3:5,1:end) = uint16(500);<br />

d(12).x(3:5,1:end)<br />

6-64

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

Saved successfully!

Ooh no, something went wrong!