Filter table based on time and make calculation

4 ビュー (過去 30 日間)
Dion Theunissen
Dion Theunissen 2021 年 7 月 19 日
編集済み: Scott MacKenzie 2021 年 7 月 19 日
I have a table like this below:
Now i want to make a loop that i can calculate the mean of a specific column based on the time. So I want to calculate the mean of 29th of june, 30th of june and so on.
Anyone who can help me with this?
  2 件のコメント
the cyclist
the cyclist 2021 年 7 月 19 日
... specificaly, upload the data in a MAT file, not just an image (which we cannot work with). If you cannot upload the whole file for some reason, just several rows that cover multiple dates would be enough.



Scott MacKenzie
Scott MacKenzie 2021 年 7 月 19 日
編集済み: Scott MacKenzie 2021 年 7 月 19 日
You don't need a loop. At a high level, here's what you need to do. Read the data into MATLAB, probably into a table using the readtable function. From there you build a timetable with one column for the date and time and other columns for the data you want to summarze. Then, use the retime function to build the summaries of interest at the desired granularity (e.g., daily). The code below does this with some random test data.
% create a datetime vector starting in June with one entry every 30 minutes
t1 = datetime(2021, 6, 1);
t2 = datetime('now');
dt = t1:hours(0.5):t2;
% create some test data, similar to data in the question
speed = rand(1,length(dt));
distance = rand(1,length(dt));
% combine the datetime elements and test data into a timetable
TT1 = timetable(dt', speed', distance', 'variablenames', {'Speed', 'Distance'} );
% compute daily means for speed and distance
TT2 = retime(TT1, 'daily', 'mean');
% plot mean speed by day
plot(TT2.Time, TT2.Speed, '-bo', 'markerfacecolor', 'b');
ylabel('Speed (units)');

その他の回答 (0 件)




Community Treasure Hunt

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

Start Hunting!

Translated by