Error using griddedInterpolant. The grid vectors must contain unique points

80 ビュー (過去 30 日間)
Hi All,
Trying to plot two different datasets with a uniform x-axis I ran through a loess filter. My code for the interp/plotting worked on one dataset, but not on another. Can't seem to figure out the issue here.
The one that worked:
% Interpolation Method
% y1 = first dataset
% yn = nth dataset
% yn = interp1(x,y,std x component,'[insert optional interp method]')
% repeat for nth datasets
y1 = interp1(x87Age,y87C,t_comp87);
y2 = interp1(x41Age,y41C,t_comp41);
plot(x87Age,y87C,'o');
hold on
plot(x41Age,y41C,'o');
plot(t_comp87,y1);
plot(t_comp41,y2);
The one that didn't work
% Interpolation Method
% y1 = first dataset
% yn = nth dataset
% yn = interp1(x,y,std x component,'[insert optional interp method]')
% repeat for nth datasets
y1 = interp1(x87Age,y87C,t_comp87);
y2 = interp1(x79Age,y79C,t_comp79);
plot(x87Age,y87C,'o');
hold on
plot(x79Age,y79C,'o');
plot(t_comp87,y1);
plot(t_comp79,y2);
Any ideas???

採用された回答

Ankitha Kollegal Arjun
Ankitha Kollegal Arjun 2017 年 7 月 24 日
This error generally occurs when there are duplicate points in the input to 'interp1'.
You can remove duplicates using 'unique' function.
For Example,
[x, index] = unique(x);
yi = interp1(x, y(index), xi);
Please apply the above logic to your code and see if it resolves the issue.
  5 件のコメント
lakshman s
lakshman s 2020 年 5 月 9 日
Suppose there are 2 points of Y for 1 value of x. Then how to get the value of both the data points? No point is duplicate for me.
Cyril Besson
Cyril Besson 2020 年 6 月 22 日
Thank you, I works very well.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeInterpolating Gridded Data についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by