i tried and had did this and i am getting expected outcomes ;
can anyone suggest any short method....
function phi = curvefit3(x,y)
clear all;
close all;
[data, ~] = xlsread('filename.xlsx');
x_imp = data((1:n),1); %%reading rows and first column
y_imp = data((1:2n),2); %%reading rows and second column
%figure;
[rows, ~] = size(data);
for i = 1: 1 : n-5 %%loop to read i+1 to i+5 rows
x = data((i+1:i+5),1);
y = data((i+1:i+5),2);
x0 = x(1);
var1 = x - x0;
var2 = var1.*var1;
%% construction of the least-squares quadratic fit to the data
%% we use the equation y =a0 + a1t + a2t^2
%% numbers a0,a1 and a2 are the unknowns
x_mat = [ones(5,1) var1 var2];
amat = x_mat'*x_mat;
bmat = x_mat'*y;
phi = inv(amat)*bmat;
a0 = phi(1);
a1 = phi(2);
a2 = phi(3);
[xfit,yfit] = func(phi,x);
figure;
plot(x,y,'or',xfit,yfit,'-xg');
%hold on;
%hold on
%plot(xfit ,yfit,'-xg'); grid;
end %for i = 1: 1 : n-5
return;
%
% calculation of function
%
function [xout,yout] = func(phi,x);
%
x0 = x(01);
x1 = x(01);
x2 = x(05);
x_array= x1:0.01:x2;
a0 = phi(1);
a1 = phi(2);
a2 = phi(3);
val = a2*(x_array-x0).^2+a1*(x_array-x0)+a0;
xout = x_array;
yout = val;
return;
this is what i was expecting