How to read an .SRT file in order to extract data ?

13 次查看(过去 30 天)
I got data of a drone's position in an .srt file that I need to analyse. I'm attaching an example file in .txt format that shows how data is organized within.
I'm used to working with .csv files or other file formats that have some very simple delimeter to set every variable apart. However, I'm struggling with figuring out what functions should I use to read this.
I simply need to be able to extract the GPS coordinates of the drone's position. In the file, the lines where that data is located looks like this:
8
00:00:08,000 --> 00:00:09,000
HOME(-68.8723,-46.0144) 2022.01.01 11:11:11
GPS(-63.7521,-43.1158,14) BAROMETER:15.0
ISO:100 Shutter:1000 EV:+1 Fnum:2.2
I'd need to extract the data that's located inside of GPS(...) and create Nx2 matrix that holds all the GPS coordinates of the file, where N is the number of data points.
Later on I might need to incorporate more data such as the Barometer info, but I think that if I could get some help in figuring out this part I could figure the rest out myself.
Thanks.

采纳的回答

Mathieu NOE
Mathieu NOE 2022-1-4
hello Elias
try this, hope it helps
%% read one file
clc
clearvars
filename = 'EXAMPLE.txt';
a = readlines(filename);
% find GPS (and barometer) data
GPS_indexes = find(contains(a,'GPS'));
for ci = 1:length(GPS_indexes)
STR = char(a(GPS_indexes(ci)));
ind1 = findstr(STR,"(");
ind2 = findstr(STR,")");
GPS_data(ci,:) = str2num(STR(ind1+1:ind2-1));
% barometer data (on same row as GPS data)
ind3 = findstr(STR,":");
barometer_data(ci,:) = str2num(STR(ind3+1:end));
end
GPS_data
barometer_data
  4 个评论

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Environment and Settings 的更多信息

产品


版本

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by