📄 samedistance.m
字号:
function [xn,yn]=samplep(x,y,N,sD,sA);
% sample point with an equal step length of curve
% N is total number of sample point.
% sD is a scale from the quantity levels of x-Data and y-Data
% sA is a scale from the length of x-axis and y-axes at the axes
% For user, sD can easier be calsulated by the data.
% sA needs that try it again and again. sA is from the
% defference of the scale at x-axis and y-axis.
% Author's email: zjliu2001@163.com
% Example:
% x=linspace(0,6,200);
% y=exp(-x.^2)/1000;
% [xn,yn]=samplep(x,y,20,1e-3,0.1);
% subplot(121);
% plot(x(1:10:end),y(1:10:end),'k-o');
% xlabel('sample at x-axis');
% subplot(122);
% plot(xn,yn,'ko');hold on;
% plot(x,y,'k');
% xlabel('sample at curve');
y=y/sD/sA;
L=0;
D=[x(1:end-1)-x(2:end)].^2+[y(1:end-1)-y(2:end)].^2;
L=sum(sqrt(D));
dL=L/[N-1];
kt=1;
Lf=0;
for k=1:length(D);
Lf(k+1)=Lf(k)+sqrt(D(k));
end
xn(1)=x(1);
yn(1)=y(1);
Nx=1;
for k=2:length(x);
if Lf(k)>=Nx*dL;
if Lf(k)==Nx*dL;
xn=[xn,x(k)];
yn=[yn,y(k)];
Nx=Nx+1;
else
Dd1=Lf(k)-Nx*dL;
Dd2=sqrt(D(k-1))-Dd1;
s=Dd1/Dd2;
xn=[xn,(x(k)+s*x(k-1))/(1+s)];
yn=[yn,(y(k)+s*y(k-1))/(1+s)];
Nx=Nx+1;
end
end
end
yn=yn*sD*sA;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -