Working with table.

2 visualizaciones (últimos 30 días)
ADITYA GUPTA
ADITYA GUPTA el 24 de Abr. de 2019
Respondida: Peter Perkins el 3 de Mayo de 2019
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"?

Respuestas (2)

Steven Lord
Steven Lord el 24 de Abr. de 2019
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 comentario
ADITYA GUPTA
ADITYA GUPTA el 24 de Abr. de 2019
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.

Iniciar sesión para comentar.


Peter Perkins
Peter Perkins el 3 de Mayo de 2019
>> 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

Categorías

Más información sobre Tables en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by