How do you use the "interp1" command?

I am working on this code and for some reason i cant sure out why im getting a error. plss lmk if you
N = 128
delta_x = 2/N
x = [0:2/N:1, 1:-2/N:0]
y_int_top = interp1 (x_c, y_top, x(1, 1:65) )
y_int_bot = interp1 (x_c, y_bot, x(1, 66:130))
y_t = [y_int_top, y_int_bot]
% for i=1:N
% x(i) = x(i-1)+delta_x
%
% theta_top(i) = atan2d((y_top(i+1)-y_top(i)),((x(i+1)-x(i))));
% theta_bot(i) = atan2d((y_bot(i+1)-y_bot(i)),((x(i+1)-x(i))));
% end

댓글 수: 4

KSSV
KSSV 2020년 11월 15일
What error you are getting? You should psecify the error and it's line number.
Diego Portillo
Diego Portillo 2020년 11월 15일
Error using interp1>reshapeAndSortXandV (line 435)
X must be a vector of type double or single.
Error in interp1 (line 128)
[X,V,orig_size_v] = reshapeAndSortXandV(X,V);
Error in compassignment (line 5)
y_int_top = interp1 (x_c, y_top, x(1, 1:65) )
KSSV
KSSV 2020년 11월 15일
What is size of x_c, y_top? Theys hould be vectors.
Diego Portillo
Diego Portillo 2020년 11월 15일
they are a tables i think. I am not very proficient with Matlab so i am not sure if they already are in vector form

댓글을 달려면 로그인하십시오.

답변 (1개)

KSSV
KSSV 2020년 11월 15일

0 개 추천

Try:
y_int_top = interp1 (x_c.(1), y_top.(1), x(1, 1:65) ) ;
y_int_bot = interp1 (x_c.(1), y_bot.(1), x(1, 66:130)) ;

댓글 수: 2

Diego Portillo
Diego Portillo 2020년 11월 15일
it now gives me a different error, idk if this one is related to the data?
```Error using matlab.internal.math.interp1
Sample points must be unique and sorted in ascending order.
Error in interp1 (line 188)
VqLite = matlab.internal.math.interp1(X,V,method,method,Xqcol);
Error in compassignment (line 5)
y_int_top = interp1 (x_c.(1), y_top.(1), x(1, 1:64) ) ;```
Try spline instead of interp1.
N = 128
delta_x = 2/N
x = [0:2/N:1, 1:-2/N:0]
y_int_top = spline(x_c, y_top, x(1, 1:65) )
y_int_bot = spline (x_c, y_bot, x(1, 66:130))
y_t = [y_int_top, y_int_bot]

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Interpolation에 대해 자세히 알아보기

태그

질문:

2020년 11월 15일

댓글:

2020년 11월 16일

Community Treasure Hunt

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

Start Hunting!

Translated by