y6=[2941, 2910, 2158, 2994, 2350, 2731, 2696, 2649, 2530, 2306, 2246, 2073, 1908, 1733, 1260, 1566, 1252, 1355, 1214, 1103, 1119];p6=polyfit(x,y6,1);%p(1) is the slope and p(2) is the intercept
yfit6=polyval(p6,x); %saves you from writing the fit equation yourself:p(1)*x +p(2)
yresid6=y6-yfit6;SSresid6 = sum(yresid6.^2);SStotal6 = (length(y6)-1) * var(y6);rsq6 = 1 - (SSresid6/SStotal6) %coefficient of determination
subplot(2,3,6)plot(x,y6,'o',x,yfit6)figureplot(x,SSresid6,'+')title('Plot of residual')
I just get a straight horizontal line. How do i fix it?
Thanks
EDIT:just realised i was plotting sum(SSresid.^2) I have added a command:
ssresid6=(y6-yfit6).^2
plot (x,ssresid6,'+')
I that the correct plot i am looking for or am i plottin something completley different here??
Best Answer