Alternative Methods for Interpolation or Solutions of Interpolation Errors
显示 更早的评论
Hi everbody.
Sometimes i give an error when making interpolation process for ex. "The values of X should be distinct error".
I have an exam this tuesday which will be done by matlab. And i am afraid of interpolation errors.
What are the alternative methods for interpolation or solutions of errors like "The values of X should be distinct" etc.?
Thanks a lot.
回答(2 个)
Walter Roberson
2015-12-7
The available techniques depend a great deal upon whether the Y corresponding to the duplicate X are the same or different.
If the Y values are the same then the major technique is to unique() the X values and take the corresponding Y values. One way of doing that is to use
XY = [X(:), Y(:)];
uXY = unique(XY,'rows');
uX = uXY(:,1);
uY = uXY(:,2);
interp1(uX, uY, locations_to_interpolate_at)
But typically one would instead construct the X values to be unique.
What are some circumstances under which you have had difficulty with duplicate X values?
Volkan Yangin
2015-12-7
0 个投票
3 个评论
Walter Roberson
2015-12-7
That is a different matter. Your X values can only grow continually or decrease continually; if your values grow and then decrease then you should not be using interp1().
If you have duplicate X but not duplicate Y then that implies that there is some X for which you have two different Y values. Given only the X value, how is the algorithm to know which of the two different Y values is intended?
interp1() should only be used for the case where the X are unique. It does not matter to interp1() if the Y are unique.
If you have a situation where the X grow until a particular time and then decrease, then you should be splitting the interpolation at the point the decrease starts, and you should be using the one that is appropriate for the time period you are in, rather than trying to do everything in one interpolation command.
Volkan Yangin
2015-12-7
John D'Errico
2015-12-7
Please do not add answers every time you wish to comment. Use the COMMENTS!!!!!!!!
类别
在 帮助中心 和 File Exchange 中查找有关 Interpolation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!