フィルターのクリア

slope of a line when intercept is forced to zero

12 ビュー (過去 30 日間)
Research
Research 2018 年 4 月 18 日
コメント済み: Research 2018 年 4 月 19 日
Hello, I have simple data set, and wants to calculate the slope when fit line is forced through the origin (0,0). I can do easily in excel. Here is my data
x = [1 2 3 4 5 6]; y = [11 61 111 161 211 261];
using y = mx + c fit equation, I get m = 50, c = -39 and r2 = 1. The fit line does not pass through origin. Now, if I force the line to pass through origin the slope (m) becomes 41 and r2 = 0.96. These are answers from Excel, but how to do this in Matlab? Any help. I tried mldivide function, but no luck.
Thanks again,
Josh

採用された回答

Rik
Rik 2018 年 4 月 18 日
編集済み: Rik 2018 年 4 月 18 日
x = [1 2 3 4 5 6]; y = [11 61 111 161 211 261];
m=x(:)\y(:);

You can find the doc if you look for mldivide.

edit: thanks for the correction/addition from Star Strider (Converting to an array with (:) always works, while my original solution with a transposition only works if the input is a row vector. I also referred to mrdivide instead of mldivide.)

  2 件のコメント
Star Strider
Star Strider 2018 年 4 月 18 日
You will have better luck reading mldivide,\ (link).
m = x(:)\y(:);
Research
Research 2018 年 4 月 19 日
Thank you.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDescriptive Statistics についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by