MATLAB: How to calculate a line-of-best-fit equation (y=mx+b) from a simple x-y dataset

line calculate

hi, my data is attach . i need solve line-of-best-fit equation (y=mx+b) from a simple x-y data

Best Answer

No data attached. If ‘x’ and ‘y’ are vectors, either of these should work:
p = [x(:) ones(size(x(:)))] \ y(:);
m = p(1);
b = p(2);
p = polyfit(x, y, 1);
m = p(1);
b = p(2);
Related Question