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

Mapping Multiple Data Types and Arrays. If the region being mapped is<br />

composed of segments of varying data types or array shapes, you can specify<br />

an individual format for each segment using an N-by-3 cell array, where N<br />

is the number of segments. The cells of each cell array row identify the data<br />

type for that segment, the array dimensions to map the data to, and a field<br />

name by which to reference that segment:<br />

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

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

datatype1, dimensions1, fieldname1; ...<br />

datatype2, dimensions2, fieldname2; ...<br />

: : : ...<br />

datatypeN, dimensionsN, fieldnameN})<br />

The following command maps a 24 kilobyte file containing data of three<br />

different data types: int16, uint32, andsingle. Theint16 data is mapped<br />

as a 2-by-2 matrix that can be accessed using the field name model. The<br />

uint32 data is a scalar value accessed as field serialno. Thesingle data<br />

isa1-by-3matrixnamedexpenses.<br />

Each of these fields belongs to the 800-by-1 structure array m.Data:<br />

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

'Offset', 2048, ...<br />

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

'int16' [2 2] 'model'; ...<br />

'uint32' [1 1] 'serialno'; ...<br />

'single' [1 3] 'expenses'});<br />

6-49

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

Saved successfully!

Ooh no, something went wrong!