How to keep only the rows with a minimum value in a specific coloumn but with the same "date" value?

1 回表示 (過去 30 日間)
It's hard to properly draw up my problem, but here's an example: I have a table:
A=[
10 00 00 3.25
10 00 40 2.12
10 00 40 2.16
10 00 40 1.85
10 00 40 1.98
10 01 12 2.45
10 01 12 2.69
]
where the first three coloumn marks the [hours minutes seconds] and the last one is a specific [value]. Now I would like to keep just one record/row at one second, and not just a random one, but the one with the smallest value in the fourth coloumn. So the final result would be:
A=[
10 00 00 3.25
10 00 40 1.85
10 01 12 2.45
]
Please note that the time of the record is not continous, and the values in the fourth coloumn are not necessary in an ascending order. Thank you in advance for any help!

採用された回答

jonas
jonas 2018 年 10 月 28 日
編集済み: jonas 2018 年 10 月 28 日
t = duration(A(:,1),A(:,2),A(:,3))
TT = timetable(t,A(:,end))
TT2 = retime(TT,unique(TT.t),'min')
TT2 =
3×1 timetable
t Var1
________ ____
10:00:00 3.25
10:00:40 1.85
10:01:12 2.45
  2 件のコメント
Marcell Szántó
Marcell Szántó 2018 年 10 月 28 日
Thank you very much, it is working pretty well! I wasn't thinking about using timetables.
jonas
jonas 2018 年 10 月 28 日
編集済み: jonas 2018 年 10 月 28 日
My pleasure! It would be equally easy to solve with grouping methods such as varfun or findgroups / splitapply, but I would strongly recommend using datetime regardless of method.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by