Introducing new rows (or columns) into an existing matrix with interpolated values to fill technically non-existent gaps.

1 次查看(过去 30 天)
I have a dataset from a GPS unit that occasionally skips a second or two. I'd like to fill in the missing time gaps with the average of the previous and subsequent rows (well actually, that wouldn't work if there was a two second gap). Note: Each time I run this, the set of GPS data will be different and may or may not have these gaps in time.
For example, here is a snippet of what the matrix of interest looks like. The first column is a reference that mathes up with other data; After that it is YY MM DD HH MM SS. As you can see, the 49th second is missing.
GPS_time = [4791 20 11 8 23 32 47; 4792 20 11 8 23 32 48; 4794 20 11 8 23 32 50; 4795 20 11 8 23 32 51]
If you don't know but would like to help, I have two thoughts on how to approach this:
1. Create a complete reference from the first and last values of the reference column with no gaps to merge with the GPS_time matrix and using fillmissing to replace the missing values. I am trying to do this now, but am having trouble.
2. Give up and use the first and last rows of data from GPS_time to re-build the matrix from scratch. This doesn't sound fun because of the way time wraps around on itself before adding to the previous columns value.
I am using R2017a, btw.

回答(1 个)

Walter Roberson
Walter Roberson 2020-12-4
Create a timetable() object and use retime() https://www.mathworks.com/help/releases/R2017a/matlab/ref/retime.html
  1 个评论
maffew
maffew 2020-12-4
Thanks for your input.
Instead of using timetable, it seems more managable to use datetime and then datevec to recreate the matrix with the missing values. This was I can easily append the reference values.
t1 = datetime(2020,11,8,23,32,47);
t2 = datetime(2020,11,8,23,49,10);
t = t1:seconds(1):t2;
t = t';
t = datevec(t);
I would still like to know how to approach my original problem because it exists with data sets that are not time at all. But I still haven't been able to find a way to interpolate "missing" data. I think I would need to use my first approach to match a complete reference to force the dataset to have NaN values and then use fillmissing.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Timetables 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by