- 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
6 ビュー (過去 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!