Sorting distance traveled by timestamps

1 次查看(过去 30 天)
I am working on extracting distance traveled with timestamps from a json file from google maps timeline data.. i have first extracted the data and ran the lat and long data through dist11km tool box to find distance treaveled between each timestamp.
now i want to sum each days travel distance and plot for each day of the week. I was working on this to to sum the distance per day. The problem is that I I am finding the temp array empty and so I am not getting any data. how should I modify this to save the find into temp and run through the sum(d2km(temp))?
for j=1:22831
temp=find(single(datenum(projecttime(1,j)))>=single(datenum('01-Sep-2019 00:00:00'))...
&single(datenum(projecttime(1,j)))<=single(datenum('02-Sep-2019 00:00:00')));
dailydis1=sum(d2km(temp));
end

采纳的回答

Guillaume
Guillaume 2019-12-6
So, you've got easy to use datetime in your array and you go and convert to harder to use datenum and then to single. Why?
The easy way to do what you want is to store all three variables in a timetable and then retime it. I'm unclear why your projecttime has one more element than the other two, I'm discarding the last here:
traveleddistance = timetable(projecttime(1:end-1)', d1km(:), d2km(:), 'VariableNames', {'d1km', 'd2km'});
dailytravel = retime(traveleddistance, 'daily', 'sum')
Done!
  1 个评论
Zachary Wayne Liesemeyer
thank you for the elegant code! i really appreaciate you convering answering this so quickly. the method I was using was suggested by my instructor and the date to num then string were my modfications.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Dates and Time 的更多信息

标签

产品


版本

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by