0

I'm trying to make a B-Spline Function

first i set the variables and made the Knot vector

# 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

then i worte a function to create the basic function

# 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

and called it in 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)];

but i get always this error in 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)]
Elteroooo
  • 2,913
  • 3
  • 33
  • 40
  • count the variables: `f(N,t,i,k,u,x,s)` has 7 inputs. `f(t,i,k-1,u+s,x,s)` has 6 – Rasman Jun 03 '12 at 14:54
  • the same Error in f (line 3) N(i,k) = ((((u-t(i)).*f(N,t,i,k-1,u+s,x,s)) / (t(i+k-1) - t(i))) + (((t(i+k)-u).*f(N,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)] – Elteroooo Jun 03 '12 at 15:39
  • no, you're get a different error. Look again. Since I don't know what you're doing I can't fix it. Specifically, you're doing: t(k+i-1), where k = 0, and i = . ergo looking at t(0), which doesn't exist – Rasman Jun 03 '12 at 17:15
  • This is quite cluttered code. Brevity in code is great but I would suggest breaking the problem line of code down into a few more lines so that you can identify the particular problem. – mathematician1975 Jun 03 '12 at 17:26

0 Answers0