plot
and colored symbols.
Calculate the linear regression using polyfit
,
and plot the regression line in the
same graph. Add title and labels, and export
the graphic to a file suitable for inclusion
in a text document.
x | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
y | -3.1 | -0.7 | 1.8 | 4.1 | 6.2 | 8.9 | 11.3 | 13.5 | 16 | 18.3 |
Solution:
>> x=0:9; >> y=[-3.1,-0.7,1.8,4.1,6.2,8.9,11.3,13.5,16,18.3]; >> plot(x,y,"+r") % Symbol: o,x,+,* >> hold Current plot held. >> plot(x,polyval(polyfit(x,y,1),x)) % Regression >> xlabel("x-Achse") >> ylabel("y-Achse") >> title("Beispielgraph") >> print("graph.eps") % not Applet or Midlet!