Linear interpolation in rows of matrix
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Gabor Pauer
am 27 Jan. 2020
Kommentiert: Star Strider
am 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 Kommentar
Mohammad Sami
am 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.
Akzeptierte Antwort
Star Strider
am 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 Kommentare
Star Strider
am 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.
Weitere Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!