Permalink
Cannot retrieve contributors at this time
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?
5011_Big_Data/memmapexample.m
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
42 lines (32 sloc)
1.09 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%% 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 |