- Read in the file
- Create vector of datetime values (see below)
- Create a time table with the datetime vector and data from the file
- Use writetimetable to write the data back into a text file.
Adding time and date column to text file
5 次查看(过去 30 天)
显示 更早的评论
I have a txt file with thousand of rows and 8 columns, example for 1 row is below
1111 2222 3333 4444 5555 6666 7777 8888
I want to add date and time as format below
3/24/2021 3:33:30 PM 1111 2222 3333 4444 5555 6666 7777 8888
Logging started 3/24/2021 at 3:33:30 and it logged after every 2 second. so the time should increase by 2 second for each row until the last n row.
3/24/2021 3:33:30 PM 1111 2222 3333 4444 5555 6666 7777 8888
3/24/2021 3:33:32 PM 1312 2003 3133 4423 5232 6123 7712 8812
.
.
.
3/25/2021 1:12:15 AM 3132 3123 5645 3242 3546 1321 1313 1215 ( this an example of the last ending row)
Please help me in this case. thank you very much.
0 个评论
回答(1 个)
Adam Danz
2021-3-24
To create the datetime vector
n is the number of rows of data which you can get after reading in the file.
n = 1000;
startingDate = datetime(2021,3,24,15,33,30,'Format','MM/dd/yyyy hh:mm:ss a');
t = startingDate + seconds(0:2:n*2-1)'
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Dates and Time 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!