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 of the Example File” on page 6-50<br />

• “Repeating a Format Scheme” on page 6-52<br />

• “Setting the Type of Access” on page 6-53<br />

All the examples in this section use a file named records.dat that contains<br />

a 5000-by-1 matrix of double-precision floating point numbers. Use the<br />

following code to generate this file before going on to the next sections of this<br />

documentation.<br />

First, save this function in your current working directory:<br />

function gendatafile(filename, count)<br />

dmax32 = double(intmax('uint32'));<br />

rand('state', 0)<br />

fid = fopen(filename,'w');<br />

fwrite(fid, rand(count,1)*dmax32, 'double');<br />

fclose(fid);<br />

Now execute the gendatafile function to generate the records.dat file<br />

that is referenced in this section. You can use this function at any time to<br />

regenerate the file:<br />

gendatafile('records.dat', 5000);<br />

Constructing the Object with Default Property Values<br />

The simplest and most general way to call the constructor is with one input<br />

argument that specifies the name of the file you want to map. All other<br />

properties are optional and are given their default values. Use the syntax<br />

shown here:<br />

objname = memmapfile(filename)<br />

To construct a map for the file records.dat that resides in your current<br />

working directory, type the following:<br />

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

m =<br />

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

6-41

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

Saved successfully!

Ooh no, something went wrong!