Time and GPS data processing

3 Ansichten (letzte 30 Tage)
Jony Smith
Jony Smith am 20 Jul. 2021
Kommentiert: Jony Smith am 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?

Antworten (2)

Simon Chan
Simon Chan am 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];
end
idx = ismember(timeofday(T.Var1),reporttime);
result = table(T(idx,:));
  1 Kommentar
Jony Smith
Jony Smith am 27 Jul. 2021
Thank you very much for the answer! Your solution helped in solving my problem!

Melden Sie sich an, um zu kommentieren.


Chunru
Chunru am 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
  3 Kommentare
Chunru
Chunru am 20 Jul. 2021
Then you can create a separate variable:
% Read data from file
T = readtable('resultcopy.txt');
% Convert to datetime format
t0 = datetime(num2str(T.Var1, '%06d'), 'InputFormat', 'HHmmss');
% Select data by comparing datetime
idx = t0 >= datetime('012600', 'InputFormat', 'HHmmss') & t0 <= datetime('012630', 'InputFormat', 'HHmmss');
T(idx, :)
ans = 31×3 table
Var1 Var2 Var3 _____ ______ _____ 12600 5103.2 15044 12601 5103.2 15044 12602 5103.2 15044 12603 5103.2 15044 12604 5103.2 15044 12605 5103.2 15044 12606 5103.2 15044 12607 5103.3 15044 12608 5103.3 15044 12609 5103.3 15044 12610 5103.3 15044 12611 5103.3 15044 12612 5103.3 15044 12613 5103.3 15044 12614 5103.3 15044 12615 5103.3 15044
Peter Perkins
Peter Perkins am 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.

Melden Sie sich an, um zu kommentieren.

Kategorien

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

Tags

Produkte


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by