How to create a function to get slope and y intercept

4 views (last 30 days)
I really new to MATLAB and I need to create a MATLAB function that computes the slope (a) and intercept (b) of a linear fit for the contained in arrays x and y, where x is the independent value and y is the dependent value. So my input would be the data (x,y), which gives me (a,b) I cannot use polyfit to figure this out, which is why I don't understand how to do it.

Answers (1)

Walter Roberson
Walter Roberson on 3 Nov 2013
You can use the \ (backslash) operator for linear fits.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!