0

我正在尝试制作 B 样条函数

首先我设置变量并制作结向量

# cmpp.m
% Set variables
k = 3;              % (8 mod 2 + 2 + 1) 
p = k - 1;          % Order = 2
n = 2*k - 1;        % Control points = 5
l = n + p + 1;      % Vector size n + p + 1 = 8

% Create the Knot vector
% Kv = [0 0 0 1 2 3 3 3] size = 8
knoten = 0;         % set all knots to 0
Kv = [];
for j=1:1:l 
    Kv = [ Kv 0 ]; 
end

for i=1:1:l
    if (i > n)
        if (i <= n) 
            Kv(i) = knoten + 1;
            knoten = knoten + 1;
        else
            Kv(i) = knoten;
        end
    else
        Kv(i) = knoten;
    end
end

然后我写了一个函数来创建基本函数

# f.m
function N = f(N,t,i,k,u,x,s)
if (u < x)
    N(i,k) = ((((u-t(i)).*f(t,i,k-1,u+s,x,s)) / (t(i+k-1) - t(i))) + (((t(i+k)-u).*f(t,i+1,k-1,u+s,x,s)) / (t(i+k) - t(i+1))));
    if ((u >= t(i)) && (u < t(i+1)))
        N(i,1) = 1;
    else
        N(i,1) = 0;
    end
end
end

并把它叫进来cmpp.m

# cmpp.m
...
...
...
N = zeros(l,k);
x = (n+1) - (k-1);
s = 1;
N = [N f(N,Kv,1,k,0,x,s)];

但我总是在 Matlab 中得到这个错误

>> cmpp
Subscripted assignment dimension mismatch.

Error in f (line 3)
    N(i,k) = ((((u-t(i)).*f(t,i,k-1,u+s,x,s)) / (t(i+k-1) - t(i))) +
    (((t(i+k)-u).*f(t,i+1,k-1,u+s,x,s)) / (t(i+k) - t(i+1))));

Error in cmpp (line 32)
N = [N f(N,Kv,1,k,0,x,s)]
4

0 回答 0