MATLAB Answers

Time and GPS data processing

2 views (last 30 days)
Jony Smith
Jony Smith on 20 Jul 2021
Commented: Jony Smith on 27 Jul 2021
Hello! I have a txt file with time data and coordinates. The time is recorded as hours-minutes-seconds without spaces. I need to select the coordinates at a certain point in time, for example: starting from 010400 30 seconds, following from 011000 30 seconds, and so on. By what means can this be done to set the necessary time intervals and the number of seconds of duration?

Answers (2)

Simon Chan
Simon Chan on 20 Jul 2021
You may edit the following three variables if you would like to set interval and duration.
initialtime = The first reporting time (example below: start from 01:26:00)
deltatime = Reporting interval (example below: every 6 minutes)
recordtime = Number of seconds you want to report for each interval. (example below: 30 seconds)
Of course, this cannot be greater than 'deltatime'
T = readtable('resultcopy.txt','Format','%{hhmmss}D %f %f');
initialtime = duration(01,26,00);
deltatime = duration(00,06,00);
recordtime = duration(00,00,30);
starttime = initialtime:deltatime:timeofday(T.Var1(end));
reporttime = [];
for k=1:length(starttime)
temp = starttime(k):duration(00,00,01):starttime(k)+recordtime-duration(00,00,01);
reporttime = [reporttime, temp];
idx = ismember(timeofday(T.Var1),reporttime);
result = table(T(idx,:));
  1 Comment
Jony Smith
Jony Smith on 27 Jul 2021
Thank you very much for the answer! Your solution helped in solving my problem!

Sign in to comment.

Chunru on 20 Jul 2021
% Read data from file
T = readtable('resultcopy.txt');
% Convert to datetime format
T.Var1 = datetime(num2str(T.Var1, '%06d'), 'InputFormat', 'HHmmss');
% Select data by comparing datetime
idx = T.Var1 >= datetime('012600', 'InputFormat', 'HHmmss') & T.Var1 <= datetime('012630', 'InputFormat', 'HHmmss');
T(idx, :)
ans = 31×3 table
Var1 Var2 Var3 ____________________ ______ _____ 20-Jul-2021 01:26:00 5103.2 15044 20-Jul-2021 01:26:01 5103.2 15044 20-Jul-2021 01:26:02 5103.2 15044 20-Jul-2021 01:26:03 5103.2 15044 20-Jul-2021 01:26:04 5103.2 15044 20-Jul-2021 01:26:05 5103.2 15044 20-Jul-2021 01:26:06 5103.2 15044 20-Jul-2021 01:26:07 5103.3 15044 20-Jul-2021 01:26:08 5103.3 15044 20-Jul-2021 01:26:09 5103.3 15044 20-Jul-2021 01:26:10 5103.3 15044 20-Jul-2021 01:26:11 5103.3 15044 20-Jul-2021 01:26:12 5103.3 15044 20-Jul-2021 01:26:13 5103.3 15044 20-Jul-2021 01:26:14 5103.3 15044 20-Jul-2021 01:26:15 5103.3 15044
Peter Perkins
Peter Perkins on 27 Jul 2021
"I don't need to convert the time to the date and time format, but I need to leave it as it is, in a string variable."
Jony, you likely don't want to do that. If you want to keep working with timestamps in that format, just set the format as Chunru more or less shows.
I'm not clear on what you need to do. "select the coordinates at a certain point in time, for example: starting from 010400 30 seconds" sounds contradictory--in any 30 sec window I assume you have multiple coordinates, so you need to say how you want to select.
You say, "for example: starting from 010400 30 seconds, following from 011000 30 seconds, and so on.", suggesting that you need to do this at many time points. My suggestion is to use a timetable, and use retime to aggregate 30 sec time bins. I can't really offer any example code, because I don't know specifically what you are trying to do.

Sign in to comment.





Community Treasure Hunt

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

Start Hunting!

Translated by