Interpolate data: not monotonic

10 ビュー (過去 30 日間)
Rafi
Rafi 2014 年 11 月 6 日
コメント済み: Star Strider 2014 年 11 月 7 日
Hey,
I am given a set of data with X and Y coordinates. The data is picturized below, with the circles corresponding to each data point. When I try to interpolate the data, to find new X coordinates for a set of Y coordinates (steps of 0.002 between minimum and maximum Y value), I get the error 'Error using griddedInterpolant. The grid vectors are not strictly monotonic increasing'. Is it because the X values constantly decrease and increase (and vice versa)?
What would be the best way to account for this so that I can still interpolate the data?

採用された回答

Star Strider
Star Strider 2014 年 11 月 7 日
You’re correct. If you want to interpolate to get more values in your situation, a bit of deception is sometimes necessary. In similar situations, I simply flip the x and y arguments to the interp1 call, and make the appropriate changes to your interpolation vector to match your y data. I would use the 'linear' method with your data.
  2 件のコメント
Rafi
Rafi 2014 年 11 月 7 日
編集済み: Rafi 2014 年 11 月 7 日
Thanks. If I understand you correctly that's what I already tried, something like the code below:
% code
y = [some given data]; % Increasing monotonic
x = [some given data]; % Not increasing monotonic
yi = [y(1):0.002:y(end)]; % Dividing into steps of 0.002
xi = interp1(y,x,yi); % 'linear' is default one
But I still get same error.
Star Strider
Star Strider 2014 年 11 月 7 日
I didn’t look too closely before, but it seems that there are two identical values at about y=-0.75. The trick is to add the smallest amount necessary to the original y-value of the one with the largest original x-value to make them monotonic and make them work with your (y,x) interp1 call. (I don’t have your data, so I can’t be specific.) This is a common technique, and it doesn’t significantly affect the accuracy of the interpolation.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeInterpolation についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by