Working with table.

21 次查看(过去 30 天)
ADITYA GUPTA
ADITYA GUPTA 2019-4-24
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"?

回答(2 个)

Steven Lord
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.
  1 个评论
ADITYA GUPTA
ADITYA GUPTA 2019-4-24
Actually I want to put the entire table data in .csv file. If this could be done using timetable than I'm fine with it. But I don't know how to do it.

请先登录,再进行评论。


Peter Perkins
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

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by