unique function usage at interp1 interpolation
12 ビュー (過去 30 日間)
古いコメントを表示
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')
0 件のコメント
回答 (2 件)
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')
0 件のコメント
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.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Resizing and Reshaping Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!