% Create the predictor variables
x1=[0:0.2:2];
x=x1+rand(size(x1))*0.1;

% create the dependent variable
y=sin(x);
y=y+randn(size(y))*0.1;

% find coeff. Of first grade polynom
p1=polyfit(x,y,1);

% find coeff. Of fourth grade polynom
p4=polyfit(x,y,4);

% evaluate the dependent variable
y1=polyval(p1,x);
y4=polyval(p4,x);

% Plot results
figure;
plot(x,y,'o');
hold on;
plot(x,y1,'g',x,y4,'m');
legend('values','linear interp.',...
'poly n=4 interp')