Sorting distance traveled by timestamps

조회 수: 2 (최근 30일)
Zachary Wayne Liesemeyer
Zachary Wayne Liesemeyer 2019년 12월 6일
댓글: Zachary Wayne Liesemeyer 2019년 12월 6일
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
Zachary Wayne Liesemeyer 2019년 12월 6일
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