Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
14 changed files
with
1,486 additions
and
0 deletions.
There are no files selected for viewing
9
foo.m
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
function y = foo(x,a,b) | ||
% Copyright 2011 The MathWorks, Inc. | ||
pause() | ||
disp('1') | ||
x(1) = x(1) + 12; | ||
pause() | ||
disp('2') | ||
y = a*x+b; | ||
pause |
BIN
+189 Bytes
matlab.mat
Binary file not shown.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
%% 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 |
3
myfunc.m
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
function y = myfunc(x) | ||
% Copyright 2011 The MathWorks, Inc. | ||
y = sin(2*x.^2+3*x+4); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
function x = myfuncInPlace(x) | ||
% Copyright 2011 The MathWorks, Inc. | ||
%% This function can operate on data in-place if called correctly. | ||
x = sin(2*x.^2+3*x+4); | ||
|
14
overhead.m
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
%% Memory Overhead for Different Kinds of Arrays | ||
% How much memory do different datatypes consume? | ||
% Copyright 2011 The MathWorks, Inc. | ||
%% | ||
% Set up | ||
clear all | ||
clc | ||
%% | ||
d = [1 2] | ||
dcell = {d} | ||
dstruct.d = d | ||
|
||
%% Look at whos Output | ||
whos |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
%% Example Showing Memory Overhead of Structures | ||
% Copyright 2011 The MathWorks, Inc. | ||
|
||
%% Load an image | ||
X = imread('onion.png'); | ||
imshow(X) | ||
whos % note that X is a 3-dimensional array | ||
|
||
%% Store one plane per field | ||
im1.red = X(:,:,1); % each plane is m x n | ||
im1.green = X(:,:,2); | ||
im1.blue = X(:,:,3); | ||
|
||
%% Store one pixel per field | ||
[nr,nc,np] = size(X); | ||
im2(nr,nc).pixel = [0 0 0]; | ||
for row = 1:nr | ||
for col = 1:nc | ||
im2(row,col).pixel = reshape(X(row,col,:),1,3); | ||
end | ||
end | ||
clear nr nc np row col | ||
|
||
%% Which one is bigger? | ||
whos im* |
32
plotDemo.m
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
% Copyright 2011 The MathWorks, Inc. | ||
%% a) | ||
% plot(data(1:100:end,1)); | ||
% ylim([1 255]); | ||
|
||
%% b) | ||
%% Down sample rate | ||
downsample=1000; | ||
|
||
%% Downsampled max/min | ||
maxdata=zeros(1,size(data,1)/downsample); | ||
mindata=zeros(1,size(data,1)/downsample); | ||
|
||
for k=1:size(data,1)/downsample | ||
section=data((k-1)*downsample+(1:downsample),1); | ||
maxdata(k)=max(section); | ||
mindata(k)=min(section); | ||
end | ||
|
||
combine=[mindata;maxdata]; | ||
plot(1:.5:(numel(combine)/2+.5),combine(:),'g'); | ||
hold on; | ||
|
||
%% Downsampled | ||
plot(data(1:downsample:end,1),'b'); | ||
ylim([1 255]); | ||
hold off; | ||
|
||
%% Annotate | ||
title('Detect Trend'); | ||
ylabel('Thickness'); | ||
xlabel('Wafer #'); |
15
precision.m
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
|
||
%% One! singular sensation, with every little byte she takes | ||
% Copyright 2011 The MathWorks, Inc. | ||
|
||
a = 1 ; % Double by default | ||
b = single(1) ; | ||
c = uint32(1) ; | ||
d = int32(1) ; | ||
e = uint16(1) ; | ||
f = int16(1) ; | ||
g = uint8(1) ; | ||
h = int8(1) ; | ||
|
||
%% | ||
i=sparse(2e9,1); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
|
||
%% Filename and Format string | ||
% This code loads in the contents of the data file with textscan a block at a | ||
% time and converts the cellarray from textscan into a double array | ||
% Copyright 2011 The MathWorks, Inc. | ||
|
||
filename='waferdata_start.csv'; | ||
FormatString=['%*f%*f%*f%*f' repmat('%f',1,9) repmat('%*f',1,7)]; | ||
|
||
%% Parameters | ||
Headers = 3 ; | ||
NumLines = 1e6 ;% Total number of lines to read | ||
BlockLines = 10000 ;% Size of block | ||
NumBlocks = NumLines/BlockLines; % Number of blocks | ||
|
||
%% Open file | ||
fid = fopen(filename); % Open file | ||
|
||
%% Preallocate data | ||
data=zeros(NumLines,9); % Pre-allocate space for data | ||
|
||
%% Get Headers | ||
cellchunk=textscan(fid,'%s',3,'delimiter','\n'); % Get first 3 lines | ||
|
||
%% Read in blocks | ||
for Block=1:NumBlocks | ||
data((Block-1)*BlockLines+(1:BlockLines),:) = ... | ||
cell2mat(textscan(fid,FormatString,BlockLines,'delimiter',',')); | ||
disp(['Block ' num2str(Block) ]); % Display current block to show progress | ||
end | ||
|
||
%% Close file | ||
fclose(fid); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
%% Filename and Format string | ||
% This code loads in the contents of the data file with textscan a block at a | ||
% time and converts the cellarray from textscan into a double array | ||
% Copyright 2011 The MathWorks, Inc. | ||
|
||
filename='waferdata.csv'; | ||
FormatString=['%*f%*f%*f%*f' repmat('%u8',1,9) repmat('%*f',1,7)]; | ||
|
||
%% Parameters | ||
Headers=3; | ||
NumLines=1e6; % Total number of lines to read | ||
BlockLines=10000; % Size of block | ||
NumBlocks=NumLines/BlockLines; % Number of blocks | ||
|
||
%% Open file | ||
fid = fopen(filename); % Open file | ||
|
||
%% Preallocate data | ||
data=zeros(NumLines,9,'uint8'); % Pre-allocate space for data | ||
|
||
%% Get Headers | ||
cellchunk=textscan(fid,'%s',3,'delimiter','\n'); % Get first 3 lines | ||
|
||
%% Read in blocks | ||
for Block=1:NumBlocks | ||
data((Block-1)*BlockLines+(1:BlockLines),:) = ... | ||
cell2mat(textscan(fid,FormatString,BlockLines,'delimiter',',')); | ||
disp(['Block ' num2str(Block) ]); % Display current block to show progress | ||
end | ||
|
||
%% Close file | ||
fclose(fid); |
BIN
+8.34 KB
waferdata.mat
Binary file not shown.
Oops, something went wrong.