How can draw a linear regression though a plot?

1 回表示 (過去 30 日間)
Joseph
Joseph 2018 年 3 月 27 日
コメント済み: Joseph 2018 年 3 月 28 日
Hi everyone I have to arrays f(32,302) and C(32,302) in which some of the elements of f and C are nan. i want to plot (plot(f,C)) and include linear regression (i tried polyfit(x,y,1)) but the problem is that because of nan values it returns y=nanX+nan. does anyone know how can I solve this problem?
thankyou
thank you

採用された回答

Walter Roberson
Walter Roberson 2018 年 3 月 27 日
"regress treats NaN values in X or y as missing values. regress omits observations with missing values from the regression fit."
  2 件のコメント
Joseph
Joseph 2018 年 3 月 27 日
編集済み: Joseph 2018 年 3 月 27 日
i tried b=regress(C,f), but it returns below error: Error using regress (line 62) Y must be a vector and must have the same number of rows as X. even though f and C arrays are the same size. i attached my f and C arrays. please take a look.
thank you
Joseph
Joseph 2018 年 3 月 28 日
I think i figured it out, I have to convert f and C matrices to vectors and remove nan values and then I can use regress(c,f) or polyfit(f,C,1) to find the linear regression of the plot.
thanks walter for your help.

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

その他の回答 (0 件)

カテゴリ

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