필터 지우기
필터 지우기

unique function usage at interp1 interpolation

조회 수: 14 (최근 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 CenterFile Exchange에서 Interpolation에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by