Sorting distance traveled by timestamps

2 Ansichten (letzte 30 Tage)
Zachary Wayne Liesemeyer
Zachary Wayne Liesemeyer am 6 Dez. 2019
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

Akzeptierte Antwort

Guillaume
Guillaume am 6 Dez. 2019
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 Kommentar
Zachary Wayne Liesemeyer
Zachary Wayne Liesemeyer am 6 Dez. 2019
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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Dates and Time finden Sie in Help Center und File Exchange

Tags

Produkte


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by