Hi!
How can I create timetable that only groups the information from the following timetable by day?
timeStamps = datetime([2017 3 4; 2017 3 5; 2017 3 4; 2017 3 5; 2017 3 4; 2017 3 5; 2017 3 4; 2017 3 5]);
hour = [8 8 8 8 9 9 9 9]';
Volume = [5 10 15 20 25 30 35 40]';
Price= [40 35 30 25 20 15 10 5]';
T= table(timeStamps, hour, Volume, Price)
TT= table2timetable(T)
This is just an example, my real timetable is composed of several days, perhaps with a for loop?

 채택된 답변

Star Strider
Star Strider 2020년 3월 31일

0 개 추천

I am not certain what you intend by ‘groups’.
One option is to use the retime function:
TTRT = retime(TT, 'daily','mean')
producing:
TTRT =
2×3 timetable
timeStamps hour Volume Price
___________ ____ ______ _____
04-Mar-2017 8.5 20 25
05-Mar-2017 8.5 25 20

댓글 수: 6

Angelavtc
Angelavtc 2020년 3월 31일
Thank you @star Strider, what I want is to divide my table by days, to create daily subtables. I dont need to do any other calculation (like the mean). I want to have a fast way of doing it as I have a dataset composed by several years, months, and of course, a lot of repeated daily observations to group. So for this small example, I will need to create 2 subtables (one for 04-Mar-2017 and the other for 05-Mar-2017) with their corresponding hour, Price and Volume observations. Thanks in advance!
Index into your timetable using a timerange.
tr = timerange(datetime('today'), 'day')
To create separate tables from ‘TT’:
G = findgroups(TT.timeStamps);
TTS = accumarray(G, (1:size(TT,1)).', [], @(x){TT(x,:)});
producing:
TTS_1 = TTS{1}
TTS_1 =
4×3 timetable
timeStamps hour Volume Price
___________ ____ ______ _____
04-Mar-2017 8 5 40
04-Mar-2017 8 15 30
04-Mar-2017 9 25 20
04-Mar-2017 9 35 10
Angelavtc
Angelavtc 2020년 3월 31일
woow @Star Strider, this works perfect! Amazing! Merci!
@Star Strider but how can I do a loop so it creates the daily subtimetables from one command. For example here, something like:
for i=1:length(TTS);
TTS_i=TTS{i};
end
Star Strider
Star Strider 2020년 3월 31일
As always, my pleasure!
My code creates them automatically. Use the addressing I used to see and use each one.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

질문:

2020년 3월 31일

댓글:

2020년 3월 31일

Community Treasure Hunt

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

Start Hunting!

Translated by