implementing linear regression for a vector with missing values

1 回表示 (過去 30 日間)
vedesh Mohit
vedesh Mohit 2018 年 4 月 2 日
コメント済み: Image Analyst 2018 年 4 月 2 日
I have two vectors x=[1 NaN 2 3 NaN 4 NaN NaN NaN 5 ]; y=[10 11 11 6 8 9 7 2 29 93 ]; I would like to know if there is a way to fit a linear regression method to the vector and estimate the missing values in x?

回答 (1 件)

KSSV
KSSV 2018 年 4 月 2 日
x=[1 NaN 2 3 NaN 4 NaN NaN NaN 5 ];
y=[10 11 11 6 8 9 7 2 29 93 ];
xi = interp1(y(~isnan(x)),x(~isnan(x))) ;
x(isnan(x))= xi ;
p = polyfit(x,y,1) ;
x1 = linspace(min(x),max(x));
y1 = polyval(p,x1);
plot(x,y,'.r') ;
hold on
plot(x1,y1)

カテゴリ

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