# How can I interpolate a datetime data series to have an interval of 1 minute in MATLAB?

16 ビュー (過去 30 日間)
Jake 2020 年 12 月 30 日
コメント済み: Ameer Hamza 2020 年 12 月 30 日
Hi everyone,
I'm analyzing a sample dataset from a .csv file (Attached). The columns are: "Ref number, MMSI, Latitude, Longitude, Timestamp (DateTime), Speed, Course". But the data is not consistent with time and, the interval between data points is not the same. Also, the data have to be grouped by the MMSI (the ID). So each ID has a set of data points but they have different time intervals.
How can I take each group of data and check their consistency, and then interpolate all the data such that, the time interval between two consecutive data points is one minute?
What I want to achieve is basically:
Data should be grouped based on MMSI - which is basically the ID. (Thanks to this community, I can get this part done without a problem)
Each group should have a consistent data series (of Latitude, Longitude, Timestamp (DateTime), Speed, Course) with a time interval of one minute between two points.
How can I approach this?

サインインしてコメントする。

### 採用された回答

Ameer Hamza 2020 年 12 月 30 日
Try something like this
[grps, unique_mmsi] = findgroups(T.mmsi);
tts = splitapply(@(la,lo,da,so,co) {timetable(da, [la lo so co])}, T(:,3:end), grps);
out = cellfun(@(tt) retime(tt, 'minutely'), tts, 'uni', 0)
The issue here is that some rows having the same mmsi have duplicate timestamps with slightly different data values. This prevents linear interpolation. For example, check row 295 and 296.
##### 9 件のコメント7 件の古いコメントを表示7 件の古いコメントを非表示
Jake 2020 年 12 月 30 日
I was following the same approach that you included in line 4!! You saved the day. Thanks a lot!
Ameer Hamza 2020 年 12 月 30 日
I am glad to be of help! :)

サインインしてコメントする。

### カテゴリ

Help Center および File ExchangePreprocessing Data についてさらに検索

### Community Treasure Hunt

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

Start Hunting!

Translated by