フィルターのクリア

How to read a .txt file and cnvert the data to a table

1 回表示 (過去 30 日間)
Kanica Sachdev
Kanica Sachdev 2023 年 4 月 28 日
コメント済み: Kanica Sachdev 2023 年 5 月 1 日
I have a .txt file with time, latitude and longitude data. I want to convert the data into a table with columns time, latitide and longitude for processing further. I have attached the file. I also want to remove the first two lines and the last line. How can I do that?
  1 件のコメント
Askic V
Askic V 2023 年 4 月 28 日
It seems to me that you first need to check the structure of your data. Some rows seems to be not placed propely.
atit1 : Time : 05:18:16.00
Latitude : 28.544998 : Longitude : 77.189e : 05:18:16.00
Latitude : 28.544998 : Longitude : 77.189971 : Time : 05:18:16.00
Latitude : 28.544998 : Longitude : 77.1899 : 05:18:16.00
Latitude : 28.544998 : Longitude : 77.189971 : Time : 05:18:16.00
Latitude : 28.544998 : Longitude : 77.1899Latitude : 28.545000 : Longitude : 77.189971 : Time : 05:18:18.00
Latitude : 28.545000 : Longitude : 77.189971 : Time : 05:18:18.00

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

採用された回答

Suraj
Suraj 2023 年 4 月 28 日
Hi Kanica
I see that you'd like to derive a table from the text file provided. You can do so with the following code:
% read the table from the file 'gps_values.txt', use space as the delimiter,
% HeaderLines is set to 2 to ingore the first two lines
raw_data = readtable('gps_values.txt', 'Delimiter', ' ', 'HeaderLines', 2, 'ReadVariableNames', false);
% create a new table with only columns 3, 8, and 13 from the original table
% These are the columns that contain the latitude, longitude and time
% respectively.
data = raw_data(:, [3 8 13]);
% assign variable names to the new table columns
data.Properties.VariableNames = {'Latitude' 'Longitude' 'Time'};
% display the new table
data
The above could should the read the data in your "gps_values.txt" file into a table. However it is worth noting that the format should be consistent at every line otherwise you may encounter errors.
Hope this helps.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLaTeX についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by