unique function usage at interp1 interpolation

12 ビュー (過去 30 日間)
fima v
fima v 2020 年 5 月 7 日
回答済み: Steven Lord 2020 年 5 月 7 日
Hello, i have imported 2D data from the attached CSV as x_data and y_data.
i have used interp1 function as shown bellow to interpolated my descrete samples into continues function as shown in the code bellow.
Matlab gave me "The grid vectors must contain unique points." error.
I have tried to solve it using 'unique' function as shown bellow but its not working,
Where did i go wrong?
Thanks.
plot(x_data,y_data)
[x, index] = unique(x);
coef_fun = @(xq) interp1(x_data, y_data(index), xq);
xq = linspace(3.5,23,100000);
plot(xq, coef_fun(xq))
title('interp1')

回答 (2 件)

KSSV
KSSV 2020 年 5 月 7 日
num = xlsread("DEfault Dataset4.csv") ;
x_data = num(:,1) ;
y_data = num(:,2) ;
plot(x_data,y_data)
[x, index] = unique(x_data);
y = y_data(index) ;
xq = linspace(min(x),max(x),100000);
yq = interp1(x,y,xq) ;
plot(xq,yq)
title('interp1')

Steven Lord
Steven Lord 2020 年 5 月 7 日
You make the elements in x unique (though maybe you intended to make x contain the unique data from x_data? That's not what you wrote.) but then you call interp1 with x_data as the X coordinates. As this code is written there's no guarantee that x_data contains only unique values.

カテゴリ

Help Center および File ExchangeResizing and Reshaping Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by