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.

Accessing Files with Memory-Mapping<br />

The following command constructs a memmapfile object for the entire file<br />

records.dat, and sets the Format property for that object to uint64. Any<br />

read or write operations made via the memory map will read and write the<br />

file contents as a sequence of unsigned 64-bit integers:<br />

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

Filename: 'd:\matlab\mfiles\records.dat'<br />

Writable: false<br />

Offset: 0<br />

Format: 'uint64'<br />

Repeat: Inf<br />

Data: 5000x1 uint64 array<br />

You can change the value of the Format property at any time after the<br />

memmapfile object is constructed. Use the object.property syntax shown<br />

here in assigning the new value:<br />

m.Format = 'int32';<br />

Further read and write operations to the region mapped by m will now treat<br />

the data in the file as a sequence of signed 32-bit integers.<br />

Property names, like Format, arenotcasesensitive.<br />

Formatting the Mapped Data to an Array. You can also specify an<br />

array shape to be applied to the data read or written to the mapped file,<br />

andafieldnametobeusedinreferencing this array. Use a cell array to<br />

hold these values either when calling the memmapfile constructor or when<br />

modifying m.Format after the object has been constructed. The cell array<br />

containsthreeelements:thedatatypetobeappliedtothemappedregion,<br />

the dimensions of the array shape that is applied to the region, and a field<br />

name to use in referencing the data:<br />

objname = memmapfile(filename, ...<br />

'Format', {datatype, dimensions, varname})<br />

The command below constructs a memmapfile object for a region of<br />

records.dat such that the contents of the region are handled by <strong>MATLAB</strong> as<br />

a 4-by-10-by-18 array of unsigned 32-bit integers, and can be referenced in the<br />

structure of the returned object using the field name x:<br />

6-47

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

Saved successfully!

Ooh no, something went wrong!