How to find the gradient and intercept if you know values of x and y?

5 ビュー (過去 30 日間)
Bob Johnson
Bob Johnson 2015 年 3 月 4 日
回答済み: Star Strider 2015 年 3 月 4 日
I have 2 columns of data, one being the x values and one being the y values. Now I've been tasked with finding the intercept and gradient using these values but I have absolutely no idea how to get started on this. Would anyone mind helping me out?

回答 (2 件)

John D'Errico
John D'Errico 2015 年 3 月 4 日
help polyfit

Star Strider
Star Strider 2015 年 3 月 4 日
Another option:
x = rand(10,1);
y = rand(10,1);
B = [ones(size(x)) x]\y;
intercept = B(1);
slope = B(2);
I used ‘slope’ rather than ‘gradient’ because gradient is also the name of a built-in MATLAB function.

カテゴリ

Help Center および File ExchangeLinear and Nonlinear Regression についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by