from Fitting NURBS to a given set of data points by Vikash Gupta
Given a set of six points a closed NURBS curve is used to approximately fit all the six data points.

evaluatefunctioninit(P,A)
function [fnvalue] = evaluatefunctioninit(P,A)
   
for i=1:length(P)
    [C(:,1),C(:,2)]=getbspline(P{i}); %generating closed B-Spline
    [sqerror,indices]=getdistance(C,A);     %computing error or the objective 
    fnvalue(i) = sqerror;
end

Contact us at files@mathworks.com