select data from the row

1 回表示 (過去 30 日間)
nada
nada 2023 年 1 月 2 日
コメント済み: Mathieu NOE 2023 年 1 月 3 日
Hi colleagues...
i have data from txt file, i want to select data from the rows number 10,11,12
* NMEA Latitude = 22 09.66 N
* NMEA Longitude = 038 29.57 E
* NMEA UTC (Time) = Oct 11 2008 02:55:45
And delete this char
str= {'* NMEA Latitude =' , '* NMEA Longitude =', '* NMEA UTC (Time)='} ;
Then convert the remainder data to a value (vector)
Latitude= 22 09.
Longitude= 038 29.57
time= Oct 11 2008 02:55:45

採用された回答

Mathieu NOE
Mathieu NOE 2023 年 1 月 2 日
hello
as far as I understood, you want lat and long as numerical values , so I opted to convert from degress / minutes format to degrees only (30° 30' = 30.5°)
for the "time" data , I am not sure what you want to do, keep it as a string or transform it to date object ?
fileDir = pwd; % define your working directory
filename = 'oc449.txt';
D=readlines(fullfile(fileDir,filename)); % read as string array
idx1=find(contains(D,'NMEA Latitude')); % find the start lines index
idx2=find(contains(D,'NMEA UTC (Time)')); % find the stop lines index
D_extract = strtrim(D(idx1:idx2));
outdata = split(D_extract,'=');
Latitude = str2double(split(strtrim(outdata(1,2)),' ')) % deg / minutes / nan
Latitude = Latitude(1)+Latitude(2)/60; % converted to deg
Longitude = str2double(split(strtrim(outdata(2,2)),' ')) % deg / minutes / nan
Longitude = Longitude(1)+Longitude(2)/60; % converted to deg
Time = strtrim(outdata(3,2)); % time as string
% convert to datetime object
Time_date = datetime(Time,'InputFormat','MMM dd yyyy HH:mm:ss');
  2 件のコメント
nada
nada 2023 年 1 月 2 日
Thank you Mathieu NOE, I really appreciate your contribution.
Mathieu NOE
Mathieu NOE 2023 年 1 月 3 日
as always, my pleasure !

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by