How to read a .txt file and cnvert the data to a table
9 次查看(过去 30 天)
显示 更早的评论
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
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
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 Exchange 中查找有关 Data Type Conversion 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!