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

m = memmapfile('mybinary.bin', 'Offset', 1024, ...<br />

'Format', 'double', 'Repeat', 1000);<br />

Get data associated with the map and plot the FFT of the first 1000 values of<br />

the map. This is when the map is actually created, because no data has been<br />

referenced until this point:<br />

plot(abs(fft(m.Data(1:1000))));<br />

Get information about the memory map:<br />

mapStruct = get(m)<br />

mapStruct =<br />

Filename: 'd:\matlab\mfiles\mybinary.bin'<br />

Writable: 0<br />

Offset: 1024<br />

Format: 'double'<br />

Repeat: 1000<br />

Data: [1000x1 double]<br />

Change the map, but continue using the same file:<br />

m.Offset = 4096;<br />

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

m.Repeat = 800;<br />

Read from a different area of the file, and plot a histogram of the data. This<br />

maps a new region and unmaps the previous region:<br />

hist(m.Data)<br />

Writing to a Mapped File<br />

Writing to a mapped file is done with standard <strong>MATLAB</strong> subscripted<br />

assignment commands. To write to a particularlocationinthefilemapped<br />

to memmapfile object m, assign the value to the m.Data structure array index<br />

andfieldthatmaptothatlocation.<br />

6-59

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

Saved successfully!

Ooh no, something went wrong!