Working with table.

조회 수: 17 (최근 30일)
ADITYA GUPTA
ADITYA GUPTA 2019년 4월 24일
답변: Peter Perkins 2019년 5월 3일
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