i have set of points in want fit line through. in cases end getting inf or -inf when lines either vertical or horizontal. have seen matlab's description of centering , scaling, not seem understand how apply data. below example code, please note isn't 1 issue. have used because main code long follow. x = [0, 1.81, 3.64, 5.45, 7.27]; y = [1, -0.82, -2.64, -4.45, -6.27]; fitline = polyfit([y(1), y(2), y(3), y(4)], [x(1), x(2), x(3), x(4)], 1); %plot data k = linspace(0, 10, 5); fk = (fitline(1)*k) + fitline(2); figure, plot(k, fk, 'color', 'r', 'linewidth', 1); looking forward help/suggestions/advice. thanks! matlab's function set polyfit , polyval handle centering (calculation of mean) , scaling (calculation of standard deviation) you. use third output of polyfit parameters: x = [0, 1.81, 3.64, 5.45, 7.27]; y = [1, -0.82, -2.64, -4.45, -6.27]; [fitline,~,mu] = polyfit(y(1:4),x(1:4), 1); and pass them polyval : k = linsp...