I try to calculate a line that can fit given several points with 2-d coordinate in MATLAB. But the result is not I expected. There may be something I understand wrong. Can anyone help me out? Thanks a lot. The code is as follows:
ptsAroundVCP_L=[180,188;177,191;174,191;171,191;168,188;] % points with 2-d coordinate
curLinePar_L=polyfit(ptsAroundVCP_L(:,2),ptsAroundVCP_L(:,1),1); % parameter of the fitted line
%% begin to plot
plotx=1:256;
figure(11);hold on;
plot(ptsAroundVCP_L(:,2),ptsAroundVCP_L(:,1),'sb');
ploty_L=polyval(curLinePar_L,plotx);
plot(plotx,ploty_L,'r');
hold off;
The output is shown as follows. But what I expected is that the fitted line should go vertically in this case. I think there is something wrong with the line fitting.

It is impossible to fit any reasonable polynomial to this data as given:
Take the transpose and you will get something reasonable: