unique function usage at interp1 interpolation
조회 수: 10 (최근 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!