Skip to content
Permalink
main
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
%% Introduction to Memory Mapping
% Copyright 2011 The MathWorks, Inc.
%% Map with default settings
% Homogeneous uint8 binary file
m=memmapfile('waferdata_uint8.bin') %#ok
%% Notice Data size==file size
fileinfo=dir('waferdata_uint8.bin');
fileinfo.bytes
%% We can access the file like it is an array
m.Data(1:20)' %#ok First few elements
%% Copy a piece an make it look like it was stored
a=reshape(m.Data(1:100),20,5)';
%% Access some in the middle
m.Data(2^20:2^20+20)' %#ok some in the middle
%% We can map the first 1MB
m.repeat=2^20 %#ok Only one megabyte
%% Or the second MB
m.offset=2^20 %#ok only one megabyte
%% Write to it
m.writable=true %#ok
m.Data(5)=100;
m.Data(1:20)' %#ok
%% Treat as n ND array
m=memmapfile('waferdata_uint8.bin','format',{'uint8' [20 100] 'x'},'repeat',20*1000) %#ok
% See it defaults to mapping the whole file as uint 8
A=m.Data; %#ok
%% Change format
m.format={'uint8' [1 4] 'headerbits';...
'uint8' [4 9] 'middle';...
'uint8' [7 1] 'tail'};
A=m.Data %#ok
m.Data(1).headerbits