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

9 Ansichten (letzte 30 Tage)
Kanica Sachdev
Kanica Sachdev am 28 Apr. 2023
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 Kommentar
Askic V
Askic V am 28 Apr. 2023
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

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Suraj
Suraj am 28 Apr. 2023
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.

Weitere Antworten (0)

Kategorien

Mehr zu Data Type Conversion finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by