Linear Fit and Axes Labeling
21 ビュー (過去 30 日間)
回答 (2 件)
Christiaan 2015 年 6 月 22 日
There are may possible ways to plot a linear fit in a scattered plot (with least squares for example). This is also called linear regression. Therefore in MATLAB you can use one of the linear regression tools.
Documentation can be found here: http://www.mathworks.com/help/stats/linear-regression-model-workflow.html
You can have a look at the examples, and then I am sure you find one that suits your problem.
Kind regards, Christiaan
Star Strider 2015 年 6 月 22 日
There are several ways to do what you want. If you have the Statistics Toolbox, consider the lsline function.
Otherwise, consider polyfit (and polyval) with a first-degree polynomial:
b = polyfit(x, y, 1);
yf = polyval(b, x);
then plot it as:
title('Scatterplot of (x,y) data')
This works best if your x-data are ordered.
See the documentation for the plot function for other options.