Interp1 Function gives back NaN in second to last datapoint

Hi everyone! Im trying to solve an issue for my graduation where i need to use interpolation. I have a dataset that i can use to simulate a full movement with help of interpolation. Somehow when i use the Interp1 function the second to last datapoint is NaN. For plotting my data this isn't a issue, because i dont use this point within my plots, but to determinate the Root Mean Squared Error i need this number to compare it with the full movement. The code i use for creating the interpolated data is as followed:
FE = a(571:603);
x = x(169:201);
Frames = [FE(1) FE(17) FE(33)];
3Int = [x(1) x(17) x(33)];
inter = interp1(Frames, 3Int, FE,'linear')
Be aware that i know the points of the complete movement. I just want to know if using an interpolation method gives back a good representation of the original dataset. I am aware that of a 33 point data set a 3 point method of interpolation isnt ideal, but it also occurs when i use more point to interpolate.
The data of FE and x are as followed:
FE:
37.8570
36.1267
34.1324
32.0503
30.2909
29.0938
26.7495
25.3398
23.2135
21.6724
19.8791
17.1966
15.7437
13.4649
11.8510
8.6762
5.8552
4.3892
2.7858
0.9258
-2.8756
-6.6230
-9.2144
-12.0599
-14.3876
-16.7708
-19.1892
-21.1271
-23.5877
-25.9523
-27.8837
-28.8928
-28.8405
x:
-0.2599
-0.2422
-0.3031
-0.3396
-0.4032
-0.4599
-0.5259
-0.6096
-0.6955
-0.7171
-0.7418
-0.7406
-0.6971
-0.6624
-0.5449
-0.4357
-0.2800
-0.1954
-0.1601
-0.0478
0.0479
0.1878
0.3040
0.4008
0.5121
0.6089
0.7325
0.8684
0.9627
1.0562
1.0962
1.0923
1.1059
Thanks in advance!

 채택된 답변

Bruno Luong
Bruno Luong 2022년 3월 31일
편집: Bruno Luong 2022년 3월 31일

0 개 추천

MATLAB interp1 by default gives NaN for query points falling outside your source points (first and last).
Use 'extrap' option (not recommended unless you know what you are doing)

추가 답변 (1개)

Torsten
Torsten 2022년 3월 31일
Frames = [FE(33) FE(17) FE(1)];
3Int = [x(33) x(17) x(1)];
instead of
Frames = [FE(1) FE(17) FE(33)];
3Int = [x(1) x(17) x(33)];
The data points must be distinct and in ascending order.
You will also use a "sort" on your full vector FE if you want to use it for interpolation.

댓글 수: 3

"The data points must be distinct and in ascending order"
descending order works fine also.
>> Frames = [FE(1) FE(17) FE(33)]
Frames =
37.8570 5.8552 -28.8405
>> issorted(Frames,'monotonic')
ans =
logical
1
Torsten
Torsten 2022년 3월 31일
편집: Torsten 2022년 3월 31일
Tast two data points in the long FE vector are not in order.
This gives the NaN values because of the extrapolation problem.
Yes i indeed can see that this causes an issue. The problem is that i cant rearange this order to sort the data. This gives an unrealistic movement that doesnt exist. This is probably a one in a 100 cases where this happens. This obviously needs to be adressed later on.

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

카테고리

도움말 센터File Exchange에서 Interpolation of 2-D Selections in 3-D Grids에 대해 자세히 알아보기

제품

릴리스

R2022a

태그

질문:

2022년 3월 31일

댓글:

2022년 3월 31일

Community Treasure Hunt

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

Start Hunting!

Translated by