function [X,Y] = b_spline(x,y,k)%k为阶数
n=length(x);
if n>3
u=rand(n+k,1);
u(1:k+1)=0;
u(n:n+k)=1;
u=sort(u);
for i=1:n-k
[xx,yy]=b_spline2(x(i:i+k),y(i:i+k),k,u(i:i+2*k));
end
end
-------------------我是分割线---------------------------------------
-------------------我是分割线---------------------------------------
-------------------我是分割线---------------------------------------
function [X,Y] = b_spline2(x,y,k,u)%x=k+1 u=2k+1
xx=cell(k,1);
yy=cell(k,1);
%(t-u(j))/(u(j+k+l-1))
t=linspace(u(k),u(k+1),11);
for j=1:k
%t=linspace(u(j),u(j+1),11);
tt=(t-u(j))/(u(j+k)-u(j));
xx{j,1}=(1-tt).*x(j)+tt.*x(j+1);
yy{j,1}=(1-tt).*y(j)+tt.*y(j+1);
end
for l=2:k
for j=l:k
%t=linspace(u(j),u(j+1),11);
tt=(t-u(j))/(u(j+k+1-l)-u(j));
xx{j-l+1,1}=(1-tt).*xx{j-l+1,1}+tt.*xx{j+1-l+1,1};
yy{j-l+1,1}=(1-tt).*yy{j-l+1,1}+tt.*yy{j+1-l+1,1};
end
end
if nargout==2
X=xx{1,1};Y=yy{1,1};
end
h=plot(X,Y);