Interp1 Function gives back NaN in second to last datapoint
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Sven Dobbe
il 31 Mar 2022
Commentato: Sven Dobbe
il 31 Mar 2022
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!
0 Commenti
Risposta accettata
Bruno Luong
il 31 Mar 2022
Modificato: Bruno Luong
il 31 Mar 2022
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)
Più risposte (1)
Torsten
il 31 Mar 2022
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.
Vedere anche
Categorie
Scopri di più su Interpolation in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!