Working with table.
21 次查看(过去 30 天)
显示 更早的评论
Hi all!
I have some data arranged in a table. I want to extract particular data values corresponding to a Date and do calculations with that value.
How can I do this?
For example:-
Let's say my data table is:
data =
date x y
____________________ ________ _________
03-Sep-2018 08:48:45 -1.3617 1.0391
29-Aug-2018 08:13:50 0.45503 -1.1176
24-Aug-2018 08:32:40 -0.84871 1.2607
19-Aug-2018 07:53:05 -0.33489 0.66014
14-Aug-2018 09:13:22 0.55278 -0.067866
So now how would I extract the value corresponding to "19-Aug-2018 07:53:05" in column "x" that is "-0.33489"?
0 个评论
回答(2 个)
Steven Lord
2019-4-24
Do you need your data to be stored in a table or would a timetable be acceptable instead? Offhand I can't think of anything you can do with a table that you can't also do with a timetable, though the reverse is not true.
If you're not tied to storing your data in a table, convert it to a timetable using table2timetable. Once you've done that you can use a datetime as a row index, or you can use timerange or withtol if you're concerned that the dates and times in the RowTimes property of your timetable include fractional seconds that may not be shown in the display. See this documentation page for examples of these techniques.
Peter Perkins
2019-5-3
>> t = table(datetime(2019,5,1:3)',[1;2;3],[4;5;6])
t =
3×3 table
Var1 Var2 Var3
___________ ____ ____
01-May-2019 1 4
02-May-2019 2 5
03-May-2019 3 6
>> tt = table2timetable(t)
tt =
3×2 timetable
Var1 Var2 Var3
___________ ____ ____
01-May-2019 1 4
02-May-2019 2 5
03-May-2019 3 6
>> tt('02-May-2019',:)
ans =
1×2 timetable
Var1 Var2 Var3
___________ ____ ____
02-May-2019 2 5
>> tt(timerange('02-May-2019','10-May-2019'),:)
ans =
2×2 timetable
Var1 Var2 Var3
___________ ____ ____
02-May-2019 2 5
03-May-2019 3 6
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!