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

This example maps a file as a sequence of 16-bit unsigned integers, and then<br />

usesthesyntaxshownabovetowriteamatrixtothefile.Maponlyasmall<br />

part of the file, using a uint16 format for this segment:<br />

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

'Offset', 2000, 'Format', 'uint16', 'Repeat', 15);<br />

Create a matrix X ofthesamesizeandwriteittothemappedpartofthefile:<br />

X = uint16(5:5:75);<br />

m.data = X;<br />

% Sequence of 5 to 75, counting by fives.<br />

Verify that new values were written to the file:<br />

m.offset = 1980; m.repeat = 35;<br />

reshape(m.data,5,7)'<br />

ans =<br />

29158 16841 32915 37696 421 %

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

Saved successfully!

Ooh no, something went wrong!