Linear Interpolation on missing data
5 次查看(过去 30 天)
显示 更早的评论
I have a time series and i tried using linear interpolation on that data. But linear interpolation seems to change the original data too (not significantly). Is there a way I can keep the values for original data same. I think i need to use a loop but not sure how to use it in linear interpolation.
1 个评论
John D'Errico
2015-9-26
Please don't add a new answer every time you wish to make a comment. Use the comments. That is why links are provided for comments. USE THEM.
回答(1 个)
Star Strider
2015-9-26
We need to see your code. The interp1 function has not (at least in my experience) changed any of the original data. Don’t use a loop if you can use interp1 or another appropriate interpolation function.
4 个评论
Star Strider
2015-9-26
That code looks as though it should work. If you end up extrapolating beyond your actual data (that will produce NaN output from interp1), you have to change your interp1 call to:
dornq = interp1(Qdorn(:,1),Qdorn(:,2),interpQ, 'linear', 'extrap');
This will work even if you don’t extrapolate.
Image Analyst
2015-9-26
How did you determine the x values stored in interpQ? If you find that the y values, dornq, at the same x value are different, then either your interpQ values don't match up with the Qdorn(:,1) values, or you're not looking at the right index.
The first case would be like your original x values are 1,2,3,5 and you're specifying interpolated x locations of 1.5, 2.5, 3.5, 4.5, and 5.5. Of course the y value at 1 is not going to be the same as the y value at 1.5
In the second case, if your original x values are 1,2,3,5, and your interpolated x values are 1,2,3,4,5, then your original y(4) will not match your new interpolated y(4) because the original y(4) was the value for x=5 while the new y(4) is the value for x=4.
Make sense? Perhaps is that what is happening?
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!