digitize.m
来自「关于matlab与digital signal的几个源程序。具体内容请自己下载看」· M 代码 · 共 76 行
M
76 行
function digitize(imgfilename,xp,yp,lines)
%
% This function can digitize as many lines as you indicate in 'lines'
% imgfilename - the filename of image file, a string
% xp - the actual data value of data points in X axis, a row vector
% yp - the actual data value of data points in Y axis, a row vector
% lines - the string name of lines, a cell array
%
a = imread([imgfilename '.bmp']);
image(a);
% number of data points in X axis
xl=length(xp);
% number of data points in Y axis
yl=length(yp);
% number of lines
nline = length(lines);
% number of times to digitize axes
naxes = 3;
Y = []; % all Ys put into one vector
YY = []; % all Ys put into a matrix
% get the data points in Y axis for several times
for i=1:naxes
[X,y]=ginput(yl);
Y = [Y;y];
YY = [YY y];
end
% pool the data points from three repetition together
A=[ones(size(Y)) Y];
% linear regression model for Y axis
yps = repmat(yp,1,naxes);
CY=A\yps';
% calculate the earror value
ym = mean(YY,2); % mean for each data point
for i=1:size(YY,2), YY(:,i)=YY(:,i)-ym;, end
yy = reshape(YY,1,size(YY,1)*size(YY,2));
yse = std(yy)
yse = CY(2) * yse
X = []; % all Ys put into one vector
XX = []; % all Ys put into a matrix
% get the data points in X axis for several times
for i=1:naxes
[x,Y]=ginput(xl);
X = [X;x];
XX = [XX x];
end
% pool the data points from three repetition together
A=[ones(size(X)) X];
% linear regression model for Y axis
xps = repmat(xp,1,naxes);
CX=A\xps';
% calculate the earror value
xm = mean(XX,2); % mean for each data point
for i=1:size(XX,2), XX(:,i)=XX(:,i)-xm;, end
xx = reshape(XX,1,size(XX,1)*size(XX,2));
xse = std(xx)
xse = CX(2) * xse
% get the data points for all lines
% after digitization of one line, press return key to advance to next line
XLine = cells(nline,1);
YLine = cells(nline,1);
for i = 1:nline
[xLine,yLine]=ginput;
XLine{i}=[ones(size(xLine)) xLine]*CX;
YLine{i}=[ones(size(yLine)) YLine]*CY;
end
figure(2);
for i = 1:nline
plot(XLine{i},YLine{i});
hold on;
DATA=[XLine{i} YLine{i}];
save([imgfilename lines{i} '.txt'],'DATA','-ascii');
end
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?