Time and GPS data processing
조회 수: 2 (최근 30일)
이전 댓글 표시
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
답변 (2개)
Simon Chan
2021년 7월 20일
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
2021년 7월 20일
% 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
Chunru
2021년 7월 20일
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
2021년 7월 27일
"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.
참고 항목
카테고리
Help Center 및 File Exchange에서 Dates and Time에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!