Computing missing values with linear fit
4 次查看(过去 30 天)
显示 更早的评论
Hi Guys.
I've got two Vectors, one has some missing values. After plotting both against each other an creating a linear fit/regression I want to calculate the missing values.
My MATLAB Version is 2017b i think.
Best
Felix
2 个评论
the cyclist
2021-8-11
编辑:the cyclist
2021-8-11
It might be helpful for you to upload your data here in a MAT file, for us to take a look.
Are the missing values in the explanatory variable ("x") or in the response variable ("y")?
Do you have the Statistics and Machine Learning Toolbox?
回答(1 个)
the cyclist
2021-8-11
% Set the random number generator seed, for reproducibility
rng default
% Make up some pretend data
N = 10;
x = (1:N)';
y = 2*x + 0.3*randn(N,1);
% Make a couple y values missing
missingIndex = [2 7];
y(missingIndex) = NaN;
% Fit the data
mdl = fitlm(x,y)
% Get the predicted values for the missing y values
y_missing_predicted = predict(mdl,x(missingIndex))
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Linear Regression 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!