Time and GPS data processing
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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?
0 Commenti
Risposte (2)
Simon Chan
il 20 Lug 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,:));
Chunru
il 20 Lug 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, :)
3 Commenti
Chunru
il 20 Lug 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, :)
Peter Perkins
il 27 Lug 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.
Vedere anche
Categorie
Scopri di più su Dates and Time in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!