Linear interpolation in rows of matrix
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Gabor Pauer
le 27 Jan 2020
Commenté : Star Strider
le 28 Jan 2020
Hi!
I have vehicle speed measurement data in the following form (small example):
Distance (from the point of measurement, in metres): 1, 2, 3, 4, 5, 6, 7
Speed of vehicle1 at these points (in km/h): 50, 54, NaN, 62, 62, 64, NaN
Speed of vehicle2 at the points: 40, NaN, NaN, NaN, 48, 54, 60
Speed of vehicle3 at the points: NaN, 60, 62, 62, 66, NaN, NaN
Speed of vehicle 4 at the points: 44, 47, NaN, 55, NaN, NaN, 58
...
I would like to get a value instead of NaN with linear interpolation. BUT I dont want to interpolate if NaNs are the first/last elements of the measurement.
Needed result of example above: [50 54 58 62 62 64 NaN; 40 42 44 46 48 54 60; NaN 60 62 62 66 NaN NaN, 44 47 51 55 56 57 58].
Im absolutely a novice user of MATLAB, but I can not handle this problem in Excel, so I really need your help. How to insert these data (in a matrix form or how?), and how to get a good result with that I can work further (there are quite a lot vehicles in this database :S) ?
Thank you in advance
Gábor
1 commentaire
Mohammad Sami
le 27 Jan 2020
If your data is in a table. use the function fillmissing.
Use the option 'EndValues','none' to avoid filling in the first and the last values.
Réponse acceptée
Star Strider
le 27 Jan 2020
D = [1, 2, 3, 4, 5, 6, 7];
V1 = [50, 54, NaN, 62, 62, 64, NaN];
V2 = [40, NaN, NaN, NaN, 48, 54, 6];
V3 = [NaN, 60, 62, 62, 66, NaN, NaN];
V4 = [44, 47, NaN, 55, NaN, NaN, 58];
Vs = [V1;V2;V3;V4];
Vout = fillmissing(Vs,'linear',2, 'EndValues','none')
producing:
Vout =
50 54 58 62 62 64 NaN
40 42 44 46 48 54 6
NaN 60 62 62 66 NaN NaN
44 47 51 55 56 57 58
As requested.
4 commentaires
Star Strider
le 28 Jan 2020
As always, my pleasure!
There were no NaN values in those data. If there were, the best approach would likely be to use the same essential logic to separate the segments, and then use fillmissing instead of interp1 on each segment.
Plus de réponses (0)
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!